SQL select return 0 if no records found, else return value

后端 未结 4 632
再見小時候
再見小時候 2021-01-24 18:02

I am now using Microsoft SQL, my code is:

   SELECT TOP 1 
   [avail]
   FROM [table1]
   where [name] = \'abc\'
   order by [datetime] desc

I

4条回答
  •  暖寄归人
    2021-01-24 18:57

    If its top 1 you want or remove top command

     SELECT TOP 1 
       isnull([avail],'0')
       FROM [table1]
       where [name] = 'abc'
       order by [datetime] desc
    

提交回复
热议问题