日期:2014-05-18  浏览次数:20370 次

这个为什么提示语法错误?
select   xmbh,   xmmc,   cast(fbsj   as   varchar)   FROM   tdcrjbxx   WHERE   (iffb   =   '1 ')  
union   all  
(select   CAST(id   AS   VARCHAR(50))   xmbh,title   xmmc,addtime   fbsj   FROM   tdjy_news   where   cataid=13)

上面的没有错

但是这样就报错了

select   *   from  
(
select   xmbh,   xmmc,   cast(fbsj   as   varchar)   FROM   tdcrjbxx   WHERE   (iffb   =   '1 ')  
union   all  
(select   CAST(id   AS   VARCHAR(50))   xmbh,title   xmmc,addtime   fbsj   FROM   tdjy_news   where   cataid=13)
)

WHY?

------解决方案--------------------
select * from
(
select xmbh, xmmc, cast(fbsj as varchar) as col1 FROM tdcrjbxx WHERE (iffb = '1 ')
union all
(select CAST(id AS VARCHAR(50)) xmbh,title xmmc,addtime fbsj FROM tdjy_news where cataid=13)
) t
------解决方案--------------------
cast(fbsj as varchar) fbsj