My first stab at producing a crosstab type output from SQL.This fails with Msg 1087, Level 15, State 2, Line 2Must declare the table variable "@p_l_summary".
except I have declared the table!The code that's breaking it isSELECT * FROM @p_l_summary AS pPIVOT ( SUM(PL_FIGURE) FOR PERIOD IN ( [200701], [200702], [200703], [200704], [200705], [200706], [200707], [200708], [200709], [200710], [200711], [200712], [200801], [200802], [200803], [200804], [200805], [200806], [200807], [200808], [200809], [200810], [200811], [200812], [200901], [200902], [200903], [200904], [200905], [200906], [200907], [200908], [200909], [200910], [200911], [200912], [201001], [201002], [201003], [201004], [201005], [201006], [201007], [201008], [201009], [201010], [201011], [201012], [201101], [201102], [201103], [201104], [201105], [201106], [201107], [201108], [201109], [201110], [201111], [201112], [201201], [201202], [201203], [201204], [201205], [201206], [201207], [201208], [201209], [201210], [201211], [201212], [201301], [201302], [201303], [201304], [201305], [201306], [201312])) AS PL_BY_MONTH
Oddly, if I addSELECT * FROM @p_l_summaryPIVOT (SUM(PL_FIGURE)FOR PERIOD IN ([201201], [201202]))AS PL_BY_MONTH
at the end of the script, it runs!Any ideas?Thanks in advance.