I have a set of data I need returned with columns being the months from the date ranges being pulled and rows would be the product(recname). Within the month columns would be totals based on the acquired date. As of now the data pulls as:
I would like it to show as
the above format should be aligned with the month calendars
I have the following Dynamic SQL:
The error I am receiving is: Msg 102, Level 15, State 1, Line 8 Incorrect syntax near '42'.
When I run the SELECT statement after STUFF in the dynamic sql above I see that 42 is the first number being pulled from Items but do not see where the syntax error could be.
Can anyone assist me please?
If you want products in rows and months as columns as you mentioned what you like to show, then you do not need a dynamic query for this.
You can use something like this example. Simply modify it to your table and column names and ad conditions into the "p" query.
The result from this query is:
answered Jan 04, 2011 at 12:05 PM
first pass guess on your code - try adding a space before the '[' in STUFF i.e.
answered Jan 04, 2011 at 12:02 PM
Kev Riley ♦♦