SQL Query Help - display records

  • Need help with Query.

    CREATE TABLE #tblTemp
    (IName varchar(50),
    ICategory varchar(20),
    IValues varchar(10))

    insert into #tblTemp values ('JSmith','Bar1','1QT')
    insert into #tblTemp values ('JSmith','Bar1','2QT')
    insert into #tblTemp values ('JSmith','Bar1','3QT')
    insert into #tblTemp values ('JSmith','Bar2','1QT')
    insert into #tblTemp values ('JSmith','Bar2','2QT')
    insert into #tblTemp values ('JSmith','Bar2','3QT')
    insert into #tblTemp values ('JSmith','Bar3','1QT')
    insert into #tblTemp values ('JSmith','Bar3','2QT')
    insert into #tblTemp values ('JSmith','Bar3','3QT')
    insert into #tblTemp values ('JSmith','Bar3','1QT')
    insert into #tblTemp values ('JSmith','Bar3','2QT')
    insert into #tblTemp values ('JSmith','Bar3','3QT')

    SELECT * FROM #tblTemp
    WHERE ICategory in ('Bar1','Bar2')

    Display records for Bar1 and Bar2, but for Bar1 category only where the IValue is 2QT and all records for Bar2 category.

    Expected Output:

    ExOutput

     

    Thanks!

  • This looks like it...

     SELECT * FROM #tblTemp
    WHERE (ICategory = 'Bar1' AND iValues = '2QT')
    OR ICategory = 'Bar2';

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

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