[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 313
  • Last Modified:

if NOT EXIST does not work for the select statment in the stored procedure even if the field is blank

if "NOT EXIST" is the type of code that for some reason  does not work for the select statment in the stored procedure even if the field is blank

Can you help write the correct code....
SELECT @user=UserId FROM tableName id = @id
IF NOT EXISTS(SELECT [test] FROM tableName WHERE  id = @id)
BEGIN

Open in new window

0
Gemini532
Asked:
Gemini532
4 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
is there a rows with id = @id ?
yes -> NOT EXISTS will return false
no -> NOT EXISTS will return true

the value of the field (ie [test]) does not matter. it can be NULL or anything else.
0
 
dqmqCommented:
Not sure what the purpose of the first line is, but this is correct syntax:


SELECT @user=UserId FROM tableName where id = @id
IF NOT EXISTS(SELECT [test] FROM tableName WHERE  id = @id)
   BEGIN
 

Open in new window

0
 
indianguru2Commented:

SELECT @user=UserId FROM tableName id = @id
IF NOT EXISTS(SELECT [test] FROM tableName WHERE  id = @id or @id is NULL)
BEGIN

Open in new window

0
 
JimFiveCommented:
SELECT @user=UserId FROM tableName id = @id
IF NOT EXISTS(SELECT [test] FROM tableName WHERE  id = @id)
BEGIN

Should that second line be:
IF NOT EXISTS(SELECT [test] FROM Tablename WHERE id = @user)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now