哎..,简单的排序问题....,
我这样写:
declare @s varchar(20)---服务线路名称
set @s= 'c1 '
declare @sql varchar(4000)--查询语句
declare @port varchar(20)
set @sql=N 'select vessel,VOY '
select @sql=@sql +N ',max(case portfuname when ' ' '+portfuname + ' ' ' then convert(varchar(10),ETDDate,120) end) [ ' +portfuname + '] '
from v_tempbasevoyage where services=@s and tt=0 group by portfuname
select @sql=@sql +N ',max(case portfuname when ' ' '+portfuname + ' ' ' then convert(varchar(10),ETADate,120) end )[ ' +portfuname + '] '
from v_tempbasevoyage where services=@s and TT> 0 group by portfuname
select @sql=@sql + N ' from v_tempbasevoyage group by services,vessel,VOY HAVing services= ' ' '+@s+ ' ' ' '
exec (@sql)
得到:
vessel voy HK cc 高雄 关岛 aa bb
西方一号ffg 2007-08-26 2007-09-10 2007-08-28 2007-09-25 2007-09-07 2007-09-15
东方一号rffd 2007-08-19 2007-09-032007-08-21 2007-09-18 2007-08-31 2007-09-08
我要把高雄这一列移到CC前面,也即:是要按日期顺序下去的.
怎么写?
当我加了order by portid,TT asc之后,老是说不包含在骤合函数中??
------解决方案--------------------帮你顶
我不知道,换列有什么好办法,我都是重做表的笨法子
我来学习~