An alternative title would be "how to join two external tables with two different values, by row, from query result". I'm open to suggestions/edits.
I have this query result (2 of 6000+ lines shown)
objectpriref packpriref locpriref
------------ ---------- ----------
30889 229 16672
30990 267 16697
and 2 tables like this
objname location
id name id name
---------.-------- ---------.----
30889 MACQ_001 16672 A16
30890 BLAH_002 16673 A17
30990 FOOH_009 16697 B300
The desired result should look something like this
objectpriref objname locname
------------ ---------- ----------
30889 MACQ_001 A16
30990 FOOH_009 B300
If this can be done within SQL, what would be the best approach? What I've tried so far:
- Put the query result into a temp table using
INTO #mtt
(for MyTempTable) from here and then trying to address the various columns as #mtt.objectpriref etc. This gets meinvalid object name #mtt
. This might deserve a separate question. - Put the query inside another select, but that runs into this, using
IN
works on single columns only.
I may be using the wrong keywords to google for. Any suggestions?