(comments are locked)
|
|
OK, you've got this a bit arse-about-face, as they say. What you want to do is something more like this, logically speaking: In other words, the second select is the one we built up in your previous query. So, something more like: Something like that. Note that I wrote that late at night and without testing anything... ;-)
Dec 12 '12 at 04:21 PM
ThomasRushton ♦
(comments are locked)
|
|
MAn i'm so close. Here is the access code This is what prints to screen: Sql error Msg 102, Level 15, State 1, Line 16 Incorrect syntax near '('. OK, looks like you've got an extra ) at the end of the PIVOT's IN clause. Also, instead of using FOR month(AdDate), use the AdDateMonth field that was created in the inner SELECT statement. For some examples and notes on the PIVOT statement, see the MS documentation at http://msdn.microsoft.com/en-us/library/ms177410(v=sql.105).aspx
Dec 12 '12 at 04:16 PM
ThomasRushton ♦
Oh yes - you'll need to include the AdCost in the inner SELECT statement, and cchange the PIVOT's SUM to just SUM(AdCost)
Dec 12 '12 at 04:22 PM
ThomasRushton ♦
(comments are locked)
|
|
Had to add few things but i thought you might like to see end result. Thank you again. SELECT Expr1, MyMfr, [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12] FROM ( SELECT Case Mfr WHEN 'Simmons' THEN 1 ELSE Case WHEN Manufacturer IS NULL THEN 3 ELSE 2 END END As Expr1, CASE WHEN Manufacturer <> '' THEN Manufacturer ELSE 'Other' END AS MyMfr, MONTH(AdDate) AS AdDateMonth, tblmain.AdCost FROM tblMain LEFT JOIN tblUpdate ON YEAR(tblMain.AdDate) = tblUpdate.[Year] LEFT JOIN tblBrand ON tblMain.Mfr = tblBrand.Manufacturer AND tblMain.Media NOT LIKE '%tv%' GROUP BY tblmain.AdDate, tblmain.AdCost, CASE Mfr WHEN 'Simmons' THEN 1 ELSE CASE WHEN Manufacturer IS NULL THEN 3 ELSE 2 END END, CASE WHEN Manufacturer <> '' THEN Manufacturer ELSE 'Other' END )P
(comments are locked)
|

