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
 General SQL Server Forums
 New to SQL Server Programming
 Where

Author  Topic 

domnet
Starting Member

1 Post

Posted - 2011-12-09 : 11:36:10
Please I have problem to extract row from MS SQL 2005 database with WHERE syntaxt. For example this does not work at all strSQL = "SELECT * FROM tblUsers WHERE User='John' "

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-09 : 11:54:44
why it doesnt work? do you've record for John in tblUsers table?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

anita.86
Starting Member

21 Posts

Posted - 2011-12-09 : 23:19:46
remove double quotes
use this query:
SELECT * FROM tblUsers WHERE User='John'



N/A
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-10 : 07:41:23
quote:
Originally posted by anita.86

remove double quotes
use this query:
SELECT * FROM tblUsers WHERE User='John'



N/A


OP might be using it inside some web application language which is why i guess the ""

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-12-12 : 04:56:37
quote:
Originally posted by domnet

Please I have problem to extract row from MS SQL 2005 database with WHERE syntaxt. For example this does not work at all strSQL = "SELECT * FROM tblUsers WHERE User='John' "


User is a keyword in SQL Server. Try using [user] instead

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

sunnyleoneo
Starting Member

19 Posts

Posted - 2011-12-12 : 06:13:53
I think User Column name conflicts with T-SQL clause keyword, Wrap the column name in brackets.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-12-15 : 03:15:25
quote:
Originally posted by sunnyleoneo

I think User Column name conflicts with T-SQL clause keyword, Wrap the column name in brackets.



Yes this is what I said in my previous reply

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-12-15 : 03:23:18
quote:
Originally posted by madhivanan

quote:
Originally posted by sunnyleoneo

I think User Column name conflicts with T-SQL clause keyword, Wrap the column name in brackets.



Yes this is what I said in my previous reply

Madhivanan

Failing to plan is Planning to fail


Dont worry too much on that
Thats one of those echo bots in action
As Don says:
Please mark the answer as accepted and move on

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2011-12-15 : 05:50:03
yeah that's pretty pernicious:

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

INSERT @foo ([user]) VALUES ('barney'),('fred')


SELECT USER FROM @foo
SELECT * FROM @foo WHERE USER = 'barney'
SELECT * FROM @foo WHERE [user] = 'barney'


All the selects are *valid* code (they all work)

but they give totally different answers.

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

- Advertisement -