我想查詢查詢是否不返回任何結果,然後打印'找不到記錄',否則執行查詢。如何在SQL Server中的else語句中編寫SQL查詢
這裏是我的查詢,
select case when exists (
SELECT CAST(dm.[ID] AS VARCHAR(100)) as ID, case when dm.[Que_Type] = 0 then 'Valid' else 'Invalid' end [Type],
dm.[Name_List], t.[Name], dm.[FromDate], dm.[ToDate] FROM tblDays dm(nolock)
inner join (select pr.ID, pr.name from tblProduct pr(nolock)) as t
on dm.TradeID = t.ID where 1=1 and dm.ToDate between GETDATE() and DATEADD(dd, 15, GETDATE()))
then 'ok'
else 'no records'
end
在此查詢,我想執行的,而不是打印「OK」查詢。我怎樣才能做到這一點?