Problem with a T-SQL 2005 PIVOT
-
I am trying to run the following query on a MS SQL Server 2005 Express.
SELECT * FROM
(
SELECT * FROM vuWeighTicketReport
WHERE [TicketDate] >= '2010-09-10'
) AS TicketData PIVOT (
SUM(ProductWeight) FOR ProductCode IN (
[Blood],[Bonecake],[Carcass],[CFat],[Desiel],[DMeal],[Feather],[FMeal],
[Greaves],[Head],[Misc],[Offal],[PBlend],[PFB],[PMeal],[Skin],[Slurry],
[Tail],[Tallow],[TBottom],[Thigh],[TMeal],[Wash]
)
)SQL Managment Studio tells me there is an error near ')' I know the error is after the
PIVOT
statement, but what the actual problem is, I don't know. I would be very grateful if someone could point my mistake out to me. ThanksSteve Jowett ------------------------- Real Programmers don't need comments -- the code is obvious.
-
I am trying to run the following query on a MS SQL Server 2005 Express.
SELECT * FROM
(
SELECT * FROM vuWeighTicketReport
WHERE [TicketDate] >= '2010-09-10'
) AS TicketData PIVOT (
SUM(ProductWeight) FOR ProductCode IN (
[Blood],[Bonecake],[Carcass],[CFat],[Desiel],[DMeal],[Feather],[FMeal],
[Greaves],[Head],[Misc],[Offal],[PBlend],[PFB],[PMeal],[Skin],[Slurry],
[Tail],[Tallow],[TBottom],[Thigh],[TMeal],[Wash]
)
)SQL Managment Studio tells me there is an error near ')' I know the error is after the
PIVOT
statement, but what the actual problem is, I don't know. I would be very grateful if someone could point my mistake out to me. ThanksSteve Jowett ------------------------- Real Programmers don't need comments -- the code is obvious.
SELECT *
FROM vuWeighTicketReport
WHERE [TicketDate] >= '2010-09-10'
AS TicketData PIVOT
(
SUM(ProductWeight) FOR ProductCode IN ([Blood],[Bonecake],[Carcass],[CFat],[Desiel],[DMeal],[Feather],FMeal],[Greaves],[Head],[Misc],[Offal],[PBlend],[PFB],[PMeal],[Skin],[Slurry],[Tail],[Tallow],TBottom],[Thigh],[TMeal],[Wash])
)try that
As barmey as a sack of badgers Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
-
SELECT *
FROM vuWeighTicketReport
WHERE [TicketDate] >= '2010-09-10'
AS TicketData PIVOT
(
SUM(ProductWeight) FOR ProductCode IN ([Blood],[Bonecake],[Carcass],[CFat],[Desiel],[DMeal],[Feather],FMeal],[Greaves],[Head],[Misc],[Offal],[PBlend],[PFB],[PMeal],[Skin],[Slurry],[Tail],[Tallow],TBottom],[Thigh],[TMeal],[Wash])
)try that
As barmey as a sack of badgers Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
Thanks for the reply, but your suggestion did not work. I have now resolved the problem, and my final SELECT query now looks like this :-
SELECT * FROM
(
SELECT * FROM vuWeighTicketReport
WHERE [TicketDate] >= '2010-09-10'
) AS Tickets PIVOT
(
SUM(ProductWeight) FOR ProductCode IN
(
[Blood],[Bonecake],[Carcass],[CFat],[Desiel],[DMeal],[Feather],
[FMeal],[Greaves],[Head],[Misc],[Offal],[PBlend],[PFB],[PMeal],
[Skin],[Slurry],[Tail],[Tallow],[TBottom],[Thigh],[TMeal],[Wash]
)
) AS TicketProductWeightsThe only difference to the original is that I have added
AS TicketProductWeights
to the end. Typically, the problem was stiring me in the face, and I couldn't see it. :doh: Thanks again.Steve Jowett ------------------------- Real Programmers don't need comments -- the code is obvious.