Sql 双管道做字符串比较?
我在SQLServer中遇到了一段我以前从未见过的代码。看起来是这样的:Sql 双管道做字符串比较?,sql,sql-server,tsql,Sql,Sql Server,Tsql,我在SQLServer中遇到了一段我以前从未见过的代码。看起来是这样的: select @cnt = 0 select @strSql = 'update SomeTable set ' if @first_name <> '||' begin select @strSql = @strSql + 'FirstName='''+ @first_name +''''
select @cnt = 0
select @strSql = 'update SomeTable set '
if @first_name <> '||'
begin
select @strSql = @strSql + 'FirstName='''+ @first_name +''''
select @cnt = @cnt+1
end
选择@cnt=0
选择@strSql='updatesometable set'
如果@first_name'| |'
开始
选择@strSql=@strSql+'FirstName='+@first_name+'''
选择@cnt=@cnt+1
结束
我的问题是,
@first_name'| |
到底做了什么?我认为双管道用于连接,但在本例中,他们是在比较first name和double管道的值?有人能解释一下吗?我从没见过这样的事。提前感谢:它检查“空”管道分隔字符串。这个手术没有什么神奇之处,只是一个小动作。代码的其余部分似乎是对的动态SQL邀请。“| |”
是字符串文字| |
是串联运算符。如果没有其余的代码,则无法判断。。。(其中$first_name
被赋值的部分)添加了double pipes不是T-SQL中的连接运算符;在此上下文中它只是一个文本。@jarlh| |
在SQL Server中不是串联运算符。它存在于Oracle和PostgreSQL中,还有一种叫做。