Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Angelflower
Starting Member
3 Posts |
Posted - 2013-10-07 : 15:49:08
|
I have query that produces a pivot table (see below). I want to use those results that in a MS Access report. Normally I would use a view for this but I can't make it a view because of the #temp table part of the code. I tried to paste the code directly into a pass-through query but it errors out and tells me that "Pass-through query with ReturnsRecords property set to True did not return any records". When I run the code in SQL I get results. Here is my pivot table:Select tbl_invoice_chart.ChartKey, tbl_invoice_chart.start_of_coverage_date as Variable , tbl_invoice_chart.SumOfqty_adj as VaribleValue into #temp123from tbl_invoice_chartwhere tbl_invoice_chart.ChartKey not like '%EA%'order by tbl_invoice_chart.start_of_coverage_date ascDECLARE @columns VARCHAR(8000)SELECT @columns = COALESCE(@columns + ',[' + cast(Variable as varchar) + ']','[' + cast(Variable as varchar)+ ']')FROM #temp123GROUP BY Variableorder by #temp123.variable ascDECLARE @query VARCHAR(8000)SET @query = 'SELECT *FROM #temp123PIVOT(MAX(VaribleValue)FOR [Variable]IN (' + @columns + '))AS p'EXECUTE(@query)DROP TABLE #temp123Sample outputColumn headings:ChartKeyFeb 1 2013 12:00AMMar 1 2013 12:00AMApr 1 2013 12:00AMMay 1 2013 12:00AMJun 1 2013 12:00AMRow data:5DZG03751Firm Gas951952966.61892.96458.5348144.400581.9781 Live well... be happy |
|
|
|
|