我在存储过程中使用了以下查询:
[_|_]
问题: IF (@rowindex = 0 AND @sectionID IN (95, 165, 231, 232) AND @Priority = 0)
BEGIN
UPDATE SpecialTagContent
SET IsVisible = CASE
WHEN @sectionID = 95 AND TagName NOT IN ('Pet Videos') THEN @IsVisible
WHEN @sectionID = 231 AND TagName NOT IN ('Ejercicios') THEN @IsVisible
ELSE @IsVisible
END
WHERE TagName NOT IN ('GMO','Gardening','Mercury Free')
AND SectionID = @sectionID
END
针对NOT IN
和@sectionID = 95
无效。但是,针对@sectionID = 231
子句的NOT IN
正在起作用。
结论 - 如果我通过WHERE
和@IsVisible=1
,那么sectionID = 95
列的所有行都应设置为IsVisible
,但1
之类的标记名除外1}}和Pet Videos
的标记名。
注意 - WHERE CLAUSE
的标记对WHERE clause
和95
都是通用的。
请帮助解决如何实现这一目标!
我错过了什么......
答案 0 :(得分:0)
更正TagName
中的额外逗号和包裹isnull()
以处理空值(coalesce()
也可以):
当TagName
为空时,not in ()
将返回null
:NOT IN clause and NULL values
IF (@rowindex = 0 AND @sectionID IN (95, 165, 231, 232) AND @Priority = 0)
BEGIN
UPDATE SpecialTagContent
SET IsVisible = CASE
WHEN @sectionID = 95
AND coalesce(TagName,'') not in ('Pet Videos')
THEN @IsVisible
WHEN @sectionID = 231
AND coalesce(TagName,'') not in ('Ejercicios')
THEN @IsVisible
ELSE @IsVisible
END
WHERE coalesce(TagName,'') NOT IN ('GMO','Gardening','Mercury Free')
AND SectionID = @sectionID
END
答案 1 :(得分:0)
它可能适合你
IF (@rowindex = 0 AND @sectionID IN ('95', '165', '231', '232') AND @Priority = 0)
BEGIN
UPDATE SpecialTagContent
SET IsVisible = CASE
WHEN (@sectionID = 95 AND TagName NOT IN ('Pet Videos') )THEN @IsVisible
WHEN (@sectionID = 231 AND TagName NOT IN ('Ejercicios') )THEN @IsVisible
ELSE @IsVisible
END
WHERE TagName NOT IN ('GMO','Gardening','Mercury Free')
AND SectionID = @sectionID
END