Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何显示空值而不是数字_Sql_Sql Server_Sql Server 2008 - Fatal编程技术网

Sql 如何显示空值而不是数字

Sql 如何显示空值而不是数字,sql,sql-server,sql-server-2008,Sql,Sql Server,Sql Server 2008,使用SQLServer2008 表1 id name 001 rahim 002 vijay 表2 id name amount 003 vijayan 08.00 004 suresh 12.00 我想使用union组合表1和表2 质疑 输出 id name amount 001 rahim 0 -- 0 should not appear, should be null 002 vijay 0 -- 0 should not apperar, should be null

使用SQLServer2008

表1

id name

001 rahim  
002 vijay
表2

id name amount

003 vijayan 08.00
004 suresh 12.00
我想使用union组合表1和表2

质疑

输出

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而不是null,因为表2的“金额”列是数字


如何处理这个问题。需要SQL查询帮助

根据Microsoft的msdn站点,关于UNION operator链接:

 select id, name, amount from table2
 union all 
 select id, name, null from table1
 order by id
列的数量和顺序必须匹配并与类型兼容

用户:卢斯卡采用了正确的方法

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