SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Feb 2005
    0 Post(s)
    0 Thread(s)

    IF EXISTS stored procedure

    I am using an If Exists statement to see if there is any data in the table. If there is it returns 1 and if not it returns 0. I am doing this so I can display an error message if the search was unsuccessful otherwise I need the data from the table to be returned so I can capture it in a dataset.

    This is the code I have so far in my stored procedure:
    	IF EXISTS(SELECT User_ID FROM dbo.User_Information 
    WHERE First_Name = @FirstName AND Last_Name = @LastName AND Email_1 = @Email)
    	RETURN 1
    How do I get it to return the information from the table?

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Toronto, Canada
    63 Post(s)
    3 Thread(s)
    if you first do the IF EXISTS SELECT, and it returns true, then you have to actually run the SELECT again in order to get the data, don't you

    therefore, don't do the IF EXIST, just do the SELECT, and then you can test the first row of the result in order to determine if there were any | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts