Sql 如何显示空值而不是数字
使用SQLServer2008 表1Sql 如何显示空值而不是数字,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
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