SQL打开或关闭变量

时间:2017-06-09 17:38:28

标签: sql-server tsql

可以打开或关闭变量吗?

从下面的代码如果我想搜索所有客户端而不仅仅是狗ppl有一个简单的方法来搜索所有或者我必须从where语句注释client = @ client out?

declare @start as date
declare @end as date
declare @client as varchar(50)
declare @Code as varchar(100)
set @start = '2017-05-28'
set @end = '2017-05-30'
set @client = 'dog ppl'
set @Code = 'in,out'
;with cte as (

select  sql code

where 
entered between @start and @end -- order date created
--finished between @start and @end --order closed
and 
client=@client
and Code in(select List from [RAT2].dbo.[tfn_SplitList](@Code,','))

1 个答案:

答案 0 :(得分:3)

使用

(client = @client or @client is null)

然后,如果您的变量为NULL,则不会在结果集中考虑它。