select COALESCE([ItemSlotX],0) as [ItemSlotX],COALESCE([ItemSlotY], 0) as [ItemSlotY] from [PowerUP_Items] where [ItemIndex]=16 and [ItemGroup]=255
在我的情況下,沒有記錄。MSSQL返回0爲空白
如果沒有找到記錄,如何返回ItemSlotX的0和ItemSlotY的0?
select COALESCE([ItemSlotX],0) as [ItemSlotX],COALESCE([ItemSlotY], 0) as [ItemSlotY] from [PowerUP_Items] where [ItemIndex]=16 and [ItemGroup]=255
在我的情況下,沒有記錄。MSSQL返回0爲空白
如果沒有找到記錄,如何返回ItemSlotX的0和ItemSlotY的0?
這?
select ItemSlotX, ItemSlotY from PowerUP_Items where ItemIndex=16 and ItemGroup=255
if @@rowcount = 0
select 0 as ItemSlotX, 0 as ItemSlotY
或者更一般的方法:
if exists (select * from PowerUP_Items where ItemIndex=16 and ItemGroup=255)
select ItemSlotX, ItemSlotY from PowerUP_Items where ItemIndex=16 and ItemGroup=255
else
select 0 as ItemSlotX, 0 as ItemSlotY
一般的做法很好,謝謝! – MeTa
如果您的查詢必須返回不超過一行,請嘗試這個
select COALESCE(max([ItemSlotX]),0) as [ItemSlotX],COALESCE(max([ItemSlotY]), 0) as [ItemSlotY]
from [PowerUP_Items] where [ItemIndex]=16 and [ItemGroup]=255
什麼數據類型是ItemSlotX和ItemSlotY? – dean
當你說空白\空你的意思是你沒有回行嗎? – sarin
列的數據類型爲int。 – MeTa