我试图确定产品表中是否已经存在某个产品。当我运行这段 tsql 代码时,它应该返回 1 并退出存储过程,因为产品 ID 7777 在产品表中不存在,但是它返回了 0。如果我不使用 if 语句,只执行 select 语句,它会说 @prodID
是 null
。我想知道为什么它没有进入 if 语句,因为我正在检查它是否为 null 值。提前感谢任何帮助。
Declare @ProdID int
select @ProdID = dbo.productTbl.ProductID
from dbo.ProductTbl
inner join dbo.OrderTbl
on dbo.ProductTbl.ProductID = dbo.OrderTbl.ProductID
where dbo.OrderTbl.ProductID = 7777
if(@ProdID = null)
begin
raiserror('The product does not exist',16,1)
return 1
end
return 0
NULL
的语法:UPDATE TABLE SET Col = NULL
- Lamak