Compare me baby

  • Hey people!

    For my user updates (THE ONES I LET THE USER UPDATE , WHICH IS THEIR INFORMATION) I have three input parameters that i send along with the select statement. They are the @email, @fName, and the @UserType. All three of these parameters i pull out of the session and send it along with the update request (user is unaware that i have included these parameters) these parameter are origionaly loaded into the session when the user logs in... So i am farely safe.

    NOW,, what i need help with is that i have now got an Admin page... so that my help can update user information easily; but in the case it does me no good to pull a session variable like the ones that i have below,, because the Admin and the user do not have the same sign-in information... OR record information as far as that goes.

    How can i create a querry that will allow me to compare these three parameters with another record.... and then.... run the select statement and return the user information .

     

    Would this be an IF statement of some kind?

    THanks!

    Erik..

     

    ALTER PROCEDURE

    AdminSystem_SelectUserInformation

    @Email

    Varchar (200),

    @FName

    Varchar (30),

    @UserType

    Varchar (20)

    AS

    Select

    FirstName,

    LastName,

    CompanyName,

    Address1,

    City,

    Zip,

    WkPhone,

    HmPhone,

    Fax,

    Title,

    Note,

    StateCD,

    CountryCD,

    Email

    From Users

    WHERE

    Email = @Email

    And

    FirstName = @FName

    And

    UserType = @UserType

    Dam again!

  • This was removed by the editor as SPAM

  • Leave your stored procedure as-is.  Change your application to first determine if the user is a customer or a worker.  If it is a customer, leave your logic alone and pass the session info into your stored procedure.  If it is a worker, prompt the worker to enter the customer's Email, Fname, and usertype.  You can then pass those values into your stored procedure and it will work just as it would if your customer was using the system? 

    It sounds like whatever you do, it will require an application change and this, to me, sounds like the most straight-forward way. 

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • He is what i have so far.

     

    my quesion is that if i get to this point and i DO NOT EXISTS.

    Does that transsql stop here?

     

    IF EXISTS

    (SELECT Email, FirstName, UserType FROM Users

    WHERE

    Email = @Admin_Email AND

    FirstName = @Admin_FName

    AND

    UserType = @Admin_UserType)

     

    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

     

    ALTER PROCEDURE

    AdminSystem_SelectConsumerInformation

    @Admin_Email

    Varchar (200), /*Admin Check */

    @Admin_FName

    Varchar (30), /*Admin Check */

    @Admin_UserType

    Varchar (20), /*Admin Check */

    @GenericColumn

    Varchar (200) ,

    @GenericValue

    Varchar (200)

    AS

    DECLARE

    @sql VARCHAR(8000)

    IF EXISTS

    (SELECT Email, FirstName, UserType FROM Users

    WHERE

    Email = @Admin_Email AND

    FirstName = @Admin_FName

    AND

    UserType = @Admin_UserType)

     

    SET

    @sql = '

    Select UserID,

    FirstName,

    LastName,

    UserType,

    ActiveInd,

    Address1,

    Address2,

    City,

    Zip,

    WkPhone,

    HmPhone,

    Fax,

    Title,

    Note,

    StateCD,

    CountryCD,

    Email

    From Users

    WHERE ' + @GenericColumn + ' = ''' + @GenericValue + ''''

    EXEC

    (@SQL)

    Dam again!

  • If your select statement cannot find a match, then SQL Server will not execute the line following the IF Exists statement.  You may want to place a BEGIN after your IF Exists if you want SQL Server to skip more than just the line directly after the IF Exists.

    John Rowan

    ======================================================
    ======================================================
    Forum Etiquette: How to post data/code on a forum to get the best help[/url] - by Jeff Moden

  • please show example.

     

    thanks!

    erik..

    Dam again!

  • Erik - something like this should help illustrate...

    /***process A "if exists" - else process B***/
    if exists(select....)
     begin
       process A
     end
    else
     begin
       process B
     end
    
    /***process A "if exists" - process B regardless of "if exists"***/
    if exists(select....)
       process A
       process B
    
    /***process both A & B only "if exists"***/
    if exists(select....)
      begin
       process A
       process B
      end
    







    **ASCII stupid question, get a stupid ANSI !!!**

  • perfect...

     

     

    thanks!

     

    erik

    Dam again!

Viewing 8 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic. Login to reply