March 5, 2008 at 1:03 am
[font="Arial"][/font] hello to all, i need a bit of help in checking a query which mssql says that there is an error but i'm quite lost on where to look..
below is the query i coded:
-- mssql server says: Incorrect syntax near the keyword 'user'.
select j.templateid as JobTemplateID, j.stateid as JobStateID,
t.functionname as JobFunctionName,
t.description as JobDescription,
u.fullname as JobOwnerName
from job as j
left outer join jobtemplate as t on j.templateid=t.id
left outer join user as u on t.owner=u.id
don't know why it refers to 'user', which is a table in my db..
all help will be gratefully appreciated.. thanks..
March 5, 2008 at 1:11 am
man oh man! 😀 i managed to run the query and get some results, just need to tweak it again for fine-tuning..
below is the corrected query
select j.templateid as JobTemplateID, j.stateid as JobStateID,
t.functionname as JobFunctionName, t.description as JobDescription,
u.fullname as JobOwnerName
from job as j
left outer join jobtemplate as t on j.templateid=t.id
left outer join as u on t.owner=u.id
the square brackets did it! heheh..:P
March 6, 2008 at 7:15 am
The Victor T. Alvarado is right.
You can put the saqure braket [] arround the user and it will work fine.
But I would like to suggest and make a rule of thumb that when ever you can used a reserve word as a table name and/or column name make sure it have a saqure bracket and you will be a champ
cheers
March 6, 2008 at 12:57 pm
Or better yet, avoid using reserved words as a column or table name! You'll also need [ ] around any names that contain spaces, i.e. [Data Base], when referencing them in TSQL statements.
-- You can't be late until you show up.
March 6, 2008 at 7:16 pm
thanks for the tip man.. im a bit rusty with my sql but its still there.. 😎
March 6, 2008 at 7:24 pm
yah, noticed that too but this db im working on is part of a package that was bought and maybe they were not careful enough to check on reserved words .. i asked for a script that will check for active jobs (stateid=4) in order to prevent a service from being stopped if any job is active/running, but guess what, they said it is impossible to do just that but i managed to devise one that performs the task..:cool:
March 7, 2008 at 6:58 am
With just a little extra effort, it's amazing what you can do! Boo to the naysayers!
-- You can't be late until you show up.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply