代码:
declare @fruit varchar(70)
set @fruit='apple'
select * from supermarket where fruitType=@fruit
如何将变量@fruit
设置为'ALL'
,这将导致select语句检索表中的所有值?
答案 0 :(得分:2)
如果您编写如下查询:
git diff
然后,如果select *
from supermarket
where fruitType=@fruit OR @fruit = 'ALL'
等于@fruit
,则'ALL'
子句的计算结果为true。
答案 1 :(得分:1)
您可以明确检查ALL
值:
SELECT *
FROM supermarket
WHERE @fruit IN ('ALL', fruitType)