Microsoft
Software
Hardware
Network
Question : Look Up in Query
Dear Experts
I am looking to make a query that, if a particular field is blank then it looks up another field in a table, else it returns the value
For example the “tbl-master” contains
Name State Country Country1
Dave Ohio
The lookup table “tbl-lookup” contains:
State Country
Alabama USA
Ohio USA
Because the country is blank in “tbl-master”, the query should look up Ohio in the lookup table “tbl-lookup” and return the value “USA” into Country1.
If Country is not blank then it returns the value from Country into Country1
If Country is blank and the query doesn’t find the state then it leaves Country1 blank
If I was doing this in excel the formula would be (in the Country1 field)
=IF(C2="",VLOOKUP(B2,'[tbl
-lookup.xl
s]Sheet1'!
$A:$B,2,FA
LSE),C2) – although this doesn’t deal with the scenario “If Country is blank and the query doesn’t find the state then it leaves Country1”
Hopefully this makes sense, can anybody help
Answer : Look Up in Query
Select m.[Name], m.[State], m.Country, IIF(nz(m.Country,'')='', l.Country, m.Country) as Country1
from [tbl-master] m
left join [tbl-lookup] l on l.[State] = m.[State]
Random Solutions
VB .NET 2005 Combine Two Tables on Primary Key and Display in DataGridView
V2P (Windows 2008)
How to avoid zero(s) in front of number(s) disappears in array
NTLDR is Missing on HP Proliant ML350 G4 with Windows 2003 SP2
FAX configuration in windows 2003 server with Gmail.
How do I verify Using SSIS if an XML file exist in the folder , change it's name and move ot to an SFTP if exist
backup exec 2010 on esxi
Audit, log and RBAC on AIX
Blackberry browser 400 error - socketexception Connection reset
Unable to view PDF files in a web browser