select case null when '' then '1' when null then '2' --ΪʲôûÓÐÔÚÕâ¸öλÖÃÅжϳöÀ´ else '3' end a
select 1 a,2 b into #a select isnull(b,0) b from #a where a=2 --bÁÐûÓÐÊý¾Ý Ó¦¸ÃÓÃʲôÀ´ÅжÏbÊÇ¿ÕµÄÄØ --bÁÐûÓÐÊý¾Ý Ó¦¸ÃÓÃʲôÀ´ÅжÏbÊÇ¿ÕµÄÄØ where b is null NULL Óë NULL ±ÈĬÈÏÊÇUNKWONEµÄ, µÚ¶þ¸ö²»ÊǺÜÃ÷°×. "ûÓÐÖµ"ºÍ"ÓÐÖµµ«ÊÇֵΪNULL"ÊÇ2¸ö¸ÅÄî,¿ÉÒÔ¼Û¸ñÅжÏ,Èç¹û·µ»Ø0ÐмǼ,ÔòÉèÖÃbΪ0 SQL code:
DECLARE @b INT SELECT @b = ISNULL(b,0) from #a WHERE a=2 IF @@ROWCOUNT = 0 SELECT @b = 0 SELECT @b AS b