Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 打开或关闭变量的SQL_Sql Server_Tsql - Fatal编程技术网

Sql server 打开或关闭变量的SQL

Sql server 打开或关闭变量的SQL,sql-server,tsql,Sql Server,Tsql,可以打开或关闭变量吗 从下面的代码中,如果我想搜索所有客户端,而不仅仅是dog ppl,那么有没有一种简单的方法可以搜索所有客户端,或者我必须从where语句中注释client=@client 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

可以打开或关闭变量吗

从下面的代码中,如果我想搜索所有客户端,而不仅仅是dog ppl,那么有没有一种简单的方法可以搜索所有客户端,或者我必须从where语句中注释client=@client

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,','))
使用

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

使用

如果变量为空,则结果集中不会考虑该变量。

请查看此帖子。看看这篇文章。
(client = @client or @client is null)