我刚刚开始将编写存储过程添加到我的 SQL 曲目中,我确信这是一个菜鸟问题。有人可以指出我在这种情况下如何使用like
运算符而不是=
运算符的正确方向吗?这样做的目的是从潜在的 5 位数字中找到前 3 个常用数字
存储过程:
create proc dbo.MultipleDrugs (@condition varchar(50))
as
SELECT *, 100.0 * round(SUM(numwithanxiety) OVER (partition BY sex) / cast(TotalSexCounts AS float), 4) overAllPercentByGender
FROM (SELECT x.sex, injurylevel, SUM(sexandlevelcounts) OVER (partition BY x.sex) numByInjury, sum(sexandlevelcounts) AS numWithAnxiety,
100.0 * round(cast(sexandlevelcounts AS float) / SUM(sexandlevelcounts) OVER (partition BY x.sex), 4) AS percentWith, y.TotalSexCounts
FROM (SELECT sex, injurylevel, COUNT(*) AS sexAndLevelCounts
FROM (SELECT DISTINCT m.patid, m.sex, m.injurylevel
FROM members AS m INNER JOIN
icdClm AS ic ON ic.patid = m.PATID
--*****when I leave this operator as like and use
--*****equals in the exec statement it works
WHERE ic.icd LIKE @condition) t
GROUP BY sex, injurylevel) x INNER JOIN
(SELECT m.sex, COUNT(DISTINCT patid) TotalSexCounts
FROM members m
GROUP BY m.sex) y ON y.sex = x.sex
GROUP BY x.sex, x.injuryLevel, x.sexAndLevelCounts, y.TotalSexCounts) rr
go
这运行,但我不能使用like
运算符
exec dbo.MultipleDrugs N'70700'
这就是我想做的
exec dbo.MultipleDrugs like '707%'