请高手帮忙看看一句SQL
Select Sa As a,Sb As b,c= '0 ',d= '0 ' From Lista Where SId = 1 Union All Select Ta As a,Tb As b,Tc As c,Td As d From Listb Where TId = 1 Order By e asc
这句话问题就出在Td上,两句分别运行,都是正确的,但是放在一起,就是不行
在Listb里面Td的类型是money,在Lista里面没有这个字段,所以我默认成了d=0
可是就是不能通过?
是类型不一样的原因么??请高手帮我看看。。谢谢了。
------解决方案--------------------把d= '0 '修改为d=0
------解决方案--------------------Select Sa As a,Sb As b,c= '0 ',d=cast(0 as money) From Lista Where SId = 1 Union All Select Ta As a,Tb As b,Tc As c,Td As d From Listb Where TId = 1 Order By e asc
------解决方案--------------------把類型改成一樣的再試試~
Select Sa As a,Sb As b,0.00 as c ,0.00 as d From Lista Where SId = 1 Union All Select Ta As a,Tb As b,Tc As c,Td As d From Listb Where TId = 1 Order By e asc
------解决方案--------------------d= '0 '此时的d是字符类型
d=0此时的d为数值类型
------解决方案--------------------or:
Select Ta As a,Tb As b,Tc As c,Td As d From Listb Where TId = 1
Union All
Select Sa As a,Sb As b,c= '0 ',d=0 From Lista Where SId = 1
--Order By e asc 这里有问题
------解决方案--------------------union all如果有些字段用常量
要么把常量的查询不写到第一个select
要么把第一个 select中的常量显式强制转换