If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > help required in writing a query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-29-03, 21:51
oimtiaz oimtiaz is offline
Registered User
 
Join Date: Oct 2003
Location: Tokyo
Posts: 10
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
Reply With Quote
  #2 (permalink)  
Old 10-30-03, 04:12
Krastio Krastio is offline
Registered User
 
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
--------------------------
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On