Saturday, February 25, 2012

Convert Query access cross tab to Query SQL Server 2005

Please help me

TRANSFORM IIf(Sum(IIf([blockinyield]=True,[SIZE],0))>0,Sum([Y_TOTAL_ton])/Sum(IIf([blockinyield]=True,[SIZE],0)),0) AS Yield_THA
SELECT OILPALM.NAME, OILPALM.YEAR, formatyear([year]) AS yearDisplay, Count(OILPALM.BLOCK) AS CountOfBLOCK
FROM OILPALM
GROUP BY OILPALM.NAME, OILPALM.YEAR
PIVOT Year([D_PLANTED]);

thank you

If you use SQL Server 2005,


Code Snippet

Declare @.PreparedStatement as varchar(1000);

Declare @.Query as varchar(1000);

Select @.PreparedStatement = ',[?]', @.Query ='';

Select @.Query = @.Query + Replace(@.PreparedStatement,'?',Year) From oilpalm Group By Year;

Select @.Query = Substring(@.Query,2,Len(@.Query))

Exec ('Select * from oilpalm PIVOT( SUM(Block) for Year In (' + @.Query + ')) as Pvt')

|||i'm sorry, but i sill don't understand with than query

No comments:

Post a Comment