如果条件不匹配,select 语句返回什么?

2024-07-04

例如,如果我有以下声明:

declare @uid int;
set @uid = (select id from tablename where condition)

在这种情况下,如果 select 没有返回结果,那么@uid be?


简而言之,它将为空

我制作了简单的临时表来测试这个

declare @temp table 
 (
   id int identity(1,1) not null  ,
   alpha nvarchar(50)
 )

 insert into @temp select 'z'

声明了一个变量nvarchar type并在此条件不满足的情况下获取值,则为 null,如果您通过 print 语句看到,则应该不会打印任何内容

declare @test nvarchar(50)


 select @test=alpha from @temp where id=70

 insert into @temp  select @test 
 select * from @temp


 print @test

我只是再次插入这个以确认有空

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如果条件不匹配,select 语句返回什么? 的相关文章

随机推荐