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