I have 2 tables country and state that has the following data.
country
=======
code value
---------------
in india
us usa
uk britain
state
code value
----------------
ca california
mi michigan
io iowa
i am getting the value for code (tempcode) from a different source. If tempcode is one among the codes that is in state table then i want to retrive the country.code as 'US' else i want to retrieve the value as it is. there is no link between the 2 tables.
Please help to provide with a sql query on this. Can we use decode function in this case.
SELECT 'US' FROM state WHERE state.code = temp.code
UNION ALL
SELECT country.code FROM country
WHERE NOT EXISTS(SELECT 'US' FROM state WHERE state.code = temp.code)
AND country.code = temp.code
Originally posted by nandu SELECT 'US' FROM state WHERE state.code = temp.code
UNION ALL
SELECT country.code FROM country
WHERE NOT EXISTS(SELECT 'US' FROM state WHERE state.code = temp.code)
AND country.code = temp.code
HTH
- Nandu
error it will not give required o/p
Abhay.
funky...
"I Dont Want To Follow A Path, I would Rather Go Where There Is No Path And Leave A Trail."
"Ego is the worst thing many have, try to overcome it & you will be the best, if not good, person on this earth"
If tempcode is one among the codes that is in state table then i want to retrive the country.code as 'US'
He doesn't say that tempcode will not contain the values of country code. He has just mentioned that
there is no link between the 2 tables.
I believe it is one of those applications(as we see on the internet)to select the state if you are residing in US etc., etc,.
I believe he wants to select the Country as US if the value in Tempcode finds a match in State table or the equivalent of the country code which the Tempcode will carry.
You have assumed the design to be in fine granularity
ie., Bangalore, Chennai.. Melbourne, Manchester etc.,
In that case he would not have post this question at all
Bookmarks