[英]Replace empty values as 0 instead of null while joining two tables in sql
我已經加入了兩個表t1和t2。 由於表t2中沒有數據,因此輸出產生一些空記錄。 我不想顯示null而是顯示0,因為我必須在Crystal報表中執行一些算術運算。 請幫我.....
樣例
declare @t table (ID int)
declare @t1 table (ID int)
insert into @t (id) values (1)
select t.ID,ISNULL(TT.ID,0)id from @t t
LEFT JOIN @t1 tt
ON t.ID = tt.ID
使用COALESCE
函數自動將null
值替換為0
。 樣品
SELECT COALESCE(total_amount, 0) from #Temp1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.