SQL Server:SELECT Everything WHEN Variable为NULL

时间:2016-07-01 17:53:07

标签: sql-server

我有代码......

DECLARE @y AS INT = xxx; --IF THIS IS NULL THEN WE WANT EVERYTHING RETURNED

SELECT column
FROM   table
WHERE  y >= @y; 

如何设置此项以便IF @y IS NULL然后忽略where子句并返回所有内容

1 个答案:

答案 0 :(得分:3)

SELECT some_column
FROM your_table
WHERE (@y is null or y >= @y)