2014-06-09 38 views
-1

使用SQL Server 2008如何顯示空值,而不是數字

table1的

id name 

001 rahim 
002 vijay 

表2

id name amount 

003 vijayan 08.00 
004 suresh 12.00 

我想用工會

查詢

於表1 &表2相結合
Select id, name, '' from table1 union Select id, name amount from table2 

輸出

id name amount 

001 rahim 0 -- 0 should not appear, should be null 
002 vijay 0 -- 0 should not apperar, should be null 
003 vijayan 08.00 
004 suresh 12.00 

0是顯示的而不是空的,因爲表2量列是數字。

如何處理此問題。需要SQL查詢幫助

回答

3
select id, name, amount from table2 
union all 
select id, name, null from table1 
order by id 
0

按照微軟的關於UNION運算符鏈接MSDN站點:msdn UNION

列的數量和順序必須匹配,並且是類型兼容。

用戶:podiluska使用正確的方法。

相關問題