SQL Query Help

  • I need help on this,

    CREATE TABLE MyTemp (ID INT,ITEM VARCHAR(10),USERID VARCHAR(15))

    GO

    INSERT INTO MyTemp (ID,ITEM,USERID) VALUES (1,'CARS','SALESPERSON')

    INSERT INTO MyTemp (ID,ITEM,USERID) VALUES (2,'CARS','MANAGER')

    INSERT INTO MyTemp (ID,ITEM,USERID) VALUES (3,'CARS','REPRESENTATIVE')

    INSERT INTO MyTemp (ID,ITEM,USERID) VALUES (4,'VAN','SALESPERSON')

    INSERT INTO MyTemp (ID,ITEM,USERID) VALUES (5,'BIKE','SALESPERSON')

    INSERT INTO MyTemp (ID,ITEM,USERID) VALUES (6,'BIKE','REPRESENTATIVE')

    INSERT INTO MyTemp (ID,ITEM,USERID) VALUES (7,'BIKE','MANAGER')

     

    I need SELECT * FROM MyTemp EXCEPT ITEM = 'BIKE'(IF USERID <> 'MANAGER')

    Looking for the following out put

    1 CARS SALESPERSON

    2 CARS MANAGER

    3 CARS REPRESENTATIVE

    4 VAN SALESPERSON

    7 BIKE MANAGER

    How can get the above output with one sql statement. Any help please.

     

    Thanks.

  • Is this what you want?

    select

     *

    from mytemp

    where

     item <> 'BIKE'

    or (item ='BIKE' AND userid = 'MANAGER')

    ???

    Regards

     

  • Thanks for your quick response.

    I did like this

    SELECT * FROM MyTemp 

    WHERE (USERID = 'MANAGER' OR ITEM <> 'BIKE')

    Thanks again.

     

Viewing 3 posts - 1 through 2 (of 2 total)

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