日期:2014-05-18 浏览次数:20646 次
declare @sql varchar(8000) set @sql = 'select t1.DOCNUM,t1.ITEMCODE,t1.ITEMNAME,t1.PLANNEDQTY ' select @sql = @sql + ' , max(case convert(varchar(10),t2.DOCDATE,120) when ''' + DOCDATE + ''' then t2.DOCNUM else null end) [DOCNUM_' + DOCDATE + ']' + ' , max(case convert(varchar(10),t2.DOCDATE,120) when ''' + DOCDATE + ''' then t2.DOCDATE else null end) [DOCDATE_' + DOCDATE + ']' + ' , max(case convert(varchar(10),t2.DOCDATE,120) when ''' + DOCDATE + ''' then t3.QUANTITY else null end) [QUANTITY_' + DOCDATE + ']' from (select distinct convert(varchar(10),DOCDATE,120) DOCDATE from OIGN ) as a set @sql = @sql + ' from OWOR t1, OIGN t2 , IGN1 t3 where t1.DOCNUM = t3.BASEREF and t3.DOCENTRY = t2.DOCENTRY group by t1.DOCNUM,t1.ITEMCODE,t1.ITEMNAME,t1.PLANNEDQTY' exec(@sql)