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
 Why is simple query unable to parse the text?

Author  Topic 

NewToASP
Starting Member

7 Posts

Posted - 2012-03-01 : 12:50:56
[code]
IF EXISTS (SELECT *
FROM ADMIN
WHERE UserName = 'jSchmoe' )
SELECT 'Exists' = 1
ELSE
SELECT 'Exists' = 0
[/code]

It is verified in the query builder but then says its unable to parse the query text. I actually need to verify if a couple of parameters exist but I can't even get this hardcoded query to work.

I just need to check if a username and password exist in the table. I have a class that will check session variables and I want to return the results of this query since it should be a boolean.


Thanks.

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2012-03-01 : 13:09:59
Perhaps
SELECT 1 AS 'Exists'


http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

MC01
Starting Member

4 Posts

Posted - 2012-03-01 : 13:11:12
I'm not sure the
SELECT 'Exists' = 1
is a valid statement. Can you run just that?

You might try making some other action, like:
IF EXISTS (SELECT * FROM admin WHERE UserName = 'jSchmoe') SELECT * FROM admin WHERE UserName = 'jSchmoe'

Alternatively, you might not do the whole exists thing in the SQL statement. In classic ASP, you might execute an SQL statement like:
SELECT * FROM admin WHERE UserName = 'jSchmoe'

Then, in ASP you can check if you got any records:

if rs.EOF then
response.write("No record found.")
else
response.write("We found a record for user: "&rs("UserName"))
end if
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-03-01 : 13:47:23
quote:
Originally posted by NewToASP


IF EXISTS (SELECT *
FROM ADMIN
WHERE UserName = 'jSchmoe' )
SELECT 'Exists' = 1
ELSE
SELECT 'Exists' = 0


It is verified in the query builder but then says its unable to parse the query text. I actually need to verify if a couple of parameters exist but I can't even get this hardcoded query to work.

I just need to check if a username and password exist in the table. I have a class that will check session variables and I want to return the results of this query since it should be a boolean.


Thanks.


Is Exists a variable?

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

Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2012-03-01 : 13:58:11
GUYS!!



SELECT 'Exists' = 1



Is the same as



SELECT 1 AS 'Exists'





Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -