这是一个简单的查询,花了很多时间但我仍然无法得到这个。
我有一个问题,如果条件为真,我需要设置一个局部变量。
Declare @asdf as nvarchar (max)
Declare @nm as nvarchar(30);
select @nm = (Select name from Core.[Lookup] where Id = 1)
Declare @dfdf as nvarchar (max)
if @nm is not null
select @asdf + 'sadf'
endif
select @nm = (Select name from Core.[Lookup] where Id = 15)
if @nm is not null
select @asdf + 'asdff'
endif
以上工作正常。但是,如果我将 select 语句更改为 set 语句,则会出现错误。'endif' 附近的语法不正确。
Declare @asdf as nvarchar (max)
Declare @nm as nvarchar(30);
select @nm = (Select name from Core.[Lookup] where Id = 1)
Declare @dfdf as nvarchar (max)
if @nm is not null
set @asdf = 'sadf'
endif
select @nm = (Select name from Core.[Lookup] where Id = 15)
if @nm is not null
set @asdf = 'asdff'
endif
谢谢