after lots of querying i got query that i want this query displays the output in cross tab format dynamically
consider i have table named SalesRepor having fields Month,Branch,Sales
declare @columns varchar(max)
declare @convert varchar(max)
select @columns = stuff (( select distinct'],[' + Month
from SalesReport
for xml path('')), 1, 2, '') + ']'
set @convert =
'select * from (select Month,Branch,Sales from SalesReport) SalesRpt
pivot(sum(Sales) for Month
in ('+@columns+')) as pivottable'
execute (@convert)