December 22, 2008 at 1:45 pm
Cany anyone explain to me why the query below does not work in SSMS 2005? Every time I run this I receive "Incorrect syntax near the keyword 'Group'." These are sample tables from the Adventure Works DB. If I remove st.Group it runs fine.
SELECT sp.SalesPersonID, sp.SalesYTD, st.Group
FROM Sales.SalesPerson sp
INNER JOIN Sales.SalesTerritory st
ON sp.TerritoryID = st.TerritoryID;
December 22, 2008 at 1:57 pm
December 22, 2008 at 2:13 pm
Luke is correct, the parser is interpreting "GROUP" as the GROUP BY phrase. you need the square brackets.
December 22, 2008 at 9:22 pm
If it's not too late, you might also consider renaming that column. It's just fewer headaches in the long run to avoid keywords as column names.
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
December 23, 2008 at 8:16 am
Adding the brackets took care of the problem. Kind of surprised that this column name was in the Adventure Works DB from Microsoft. Another lesson learned.
December 23, 2008 at 8:16 am
Thanks for everyones help.
December 23, 2008 at 8:26 am
yeah, it's lovely when MS doesn't even follow it's own rules when it comes to reserved words. I currently work with a db where some brain trust added the column [case] to about 1/3 of the tables. Luckily, I have SQL Prompt configured to always add brackets for me now, so it's less annoying, but...
-Luke.
December 23, 2008 at 8:47 am
Sorry I blew over that this was out of Adventureworks.
Merry Christmas to all. May 2009 be a better year for everyone.
__________________________________________________
Against stupidity the gods themselves contend in vain. -- Friedrich Schiller
Stop, children, what's that sound? Everybody look what's going down. -- Stephen Stills
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply