Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 SQL Reserved Word

Author  Topic 

keanhoo168
Starting Member

2 Posts

Posted - 2010-04-13 : 03:43:20
I have a table with a field named "USER" in the table.
When i issue a query SELECT * FROM table WHERE user = 'ABC',
it always show me all the data in the table.
When i check through the reserved word list, i found that 'USER' itself is a reserved word in SQL.
How should i modify my query statement so that i get the result i want?

Thank you.

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-13 : 04:39:44
Try
SELECT * FROM table WHERE [user] = 'ABC'

If that is not the solution then show your original query please.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2010-04-13 : 04:45:04
by default

SELECT user

returns the schema name. (if I run this on my db I get 'dbo' returned. The following SQL returns all rows in @foo for example

DECLARE @foo TABLE (
[user] VARCHAR(255)
)

INSERT @foo ([user])
SELECT 'abc'
UNION SELECT 'def'

SELECT * FROM @foo

SELECT * FROM @foo WHERE user = 'abc'

SELECT * FROM @foo WHERE user = 'dbo'




Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-04-13 : 05:01:08
That's interesting - so the square brackets should bring the solutuion.


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

keanhoo168
Starting Member

2 Posts

Posted - 2010-04-13 : 21:07:04
I try SELECT * FROM qgpl.zsu WHERE [user] = 'abc';
The result i get is following error:
[SQL0104] Token [ was not valid. Valid tokens: ( + - ? : DAY NOT RRN CASE CAST CHAR DAYS HOUR LEFT TRIM USER.
Any escape character can be used in this case?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-13 : 22:33:43
I don't think that error is a Microsoft SQL Server error. Are you running some other database platform?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-04-13 : 23:21:40
quote:
Originally posted by keanhoo168

I try SELECT * FROM qgpl.zsu WHERE [user] = 'abc';
The result i get is following error:
[SQL0104] Token [ was not valid. Valid tokens: ( + - ? : DAY NOT RRN CASE CAST CHAR DAYS HOUR LEFT TRIM USER.
Any escape character can be used in this case?



Looks like you are not using Microsoft SQL Server 2000. Googling on the error message leads to DB2.

This is a Microsoft SQL Server forum. Try posting your question over at a DB2 forum.


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-13 : 23:37:42
Maybe this will help: http://www.ispirer.com/doc/sqlways39/Output/SQLWays-1-038.html

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -