返回没有行的select语句的值

时间:2011-11-28 13:14:24

标签: sql sql-server sql-server-2005

如果我做了以下陈述:

set @ParentMemberID = (select MemberID from tblMembers where ThirdPartyReference like @Branch_ThirdPartyReference)

没有结果。 @ParentMemberID的价值是什么?

由于

3 个答案:

答案 0 :(得分:4)

只需使用SELECT关键字

自行检查价值
 set @ParentMemberID = (select MemberID from tblMembers where ThirdPartyReference like @Branch_ThirdPartyReference)

 --This will show you the value of @ParentMemberID 
 SELECT @ParentMemberID

答案 1 :(得分:2)

简化测试

declare @I int
set @I = 0
set @I = (select 1 where 0 = 1)
select @I

结果:

NULL

答案 2 :(得分:0)

可能在下面是查询您要查找的内容,请使用它,

SET @ParentMemberID = ISNULL((SELECT MemberID FROM tblMembers 
          WHERE ThirdPartyReference LIKE @Branch_ThirdPartyReference), 0)

SELECT @ParentMemberID 

编辑:

如果您不需要检查NULL,那么下面的查询将完全适应:

SET @ParentMemberID = (SELECT MemberID FROM tblMembers 
          WHERE ThirdPartyReference LIKE @Branch_ThirdPartyReference)

SELECT @ParentMemberID