Click here to Skip to main content
15,909,466 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Table
1. Entity
EntityId Name
1 Rajni
2 neha

2. License

LicenseId EntityId LicenseType
1. 1 I
2. 2 F

3. EntityAddress

AddressId Entity AddressType City State
1 1 MLG Ggn Haryana
2 1 BUS HHN Up
3 2 MLG XY kl
4 2 BUS GH HJ

Now, I want to extract City n state on basis of EntityId n LicenseType
if LicenseType "I",THEN AddressType "MLG" city n state come
if LicenseType "F",THEN AddressType "BUS" city n state come
Posted

Please try this Query.
As far as I understood ur question, this is the query what u r asking.
sorry if misunderstood.if not please give me some more clarity.

SELECT EA.City,EA.State,EA.AddressType FROM EntityAddress EA INNER JOIN License L ON EA.EntityId=L.EntityId WHERE L.LicenseType="GivenLicenseType"
 
Share this answer
 
v3
Try this.

SQL
select L.LicenseType, EA.Address,EA.city,EA.sate from Entity E 
left outer join License L on E.EntityId = L.EntityId
left outer join EntityAddress EA on EA.Entity = L.EntityId
where E.EntityId = <entityid> and L.LicenseType = '<licensetype>'</licensetype></entityid>
 
Share this answer
 
select L.LicenseType, EA.Address,EA.city,EA.sate
from Entity E
left outer join License L
on E.EntityId = L.EntityId
left outer join EntityAddress EA
on EA.Entity = L.EntityId
WHERE (L.licenseType='I' AND EA.AddressType='MLG')
OR (L.licenseType='F' AND EA.AddressType='BUS')
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900