Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2003
    Location
    Tokyo
    Posts
    10

    Unanswered: help required in writing a query

    hi all,

    consider the following scenario:

    I have 2 tables ModelSalesUnitCode and SalesUnitCode with following data:

    ModelSalesUnit
    Kis Type Salu_cd
    PC 6 2AA01
    WA 3 2AA01
    Wa 3 3AA01

    SalesUnitCode
    Salu_cd Kis Type Salu_desc
    2AA01 null null generic description
    2AA01 WA 3 WA description
    3AA01 WA 3 generic description

    Now I write this query to get the salu_cd and their respective descriptions for the model with (kis = WA and Type = 3)

    Select
    a.kis,
    a.type,
    a.salu_cd,
    b.salu_desc
    From
    modelsalesunitcode a, salesunitcode b
    Where
    b.salu_cd = a.salu_cd
    And
    a.kis = 'WA'
    And
    a.type = '3'

    This gives me
    kis type salu_cd salu_desc
    WA 3 2AA01 generic description
    WA 3 2AA01 WA description
    WA 3 3AA01 generic description

    is it possible to modify the above query in such a way that it returns

    kis type salu_cd salu_desc
    WA 3 2AA01 WA description
    WA 3 3AA01 generic description

    meaning where description exists for (Kis = WA and Type = 3) pick it up (WA Description in above case) if it does not exist then pick the generic description.

    Thanx in advance
    Omer


    /
    Omer Imtiaz

  2. #2
    Join Date
    Oct 2003
    Location
    Sofia
    Posts
    16
    Add clause in WHERE:

    Select
    a.kis,
    a.type,
    a.salu_cd,
    b.salu_desc
    From
    modelsalesunitcode a, salesunitcode b
    Where
    b.salu_cd = a.salu_cd
    And
    a.kis = 'WA'
    And
    a.type = '3'
    --------------------------
    AND b.kis IS NOT NULL
    --------------------------

Posting Permissions

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