I have a query which has a column (PROCESS) which was obtained using a concat function. Now i need to lookup this column in a column which is on another table (Table2) and then return a value from the same table (table 2).
My Current output will look like this.
I have a reference Table like this.
I need to lookup "Process" (Query Result) in "Type" (the reference Table) and return "Description" (Ref table) in "Process Column".
Final Output should look like this
I'm unable to figure out how to modify my query to do this. pls help.
You need a join . Join your reference table to your other query based on the concatenated value and you can display the description you are looking for.
FROM #Source As s) D INNER JOIN [Reference Table] AS rt ON d.Process = rt.type
You need an INNER JOIN
between Source
and Reference
tables for your nested query with the JOIN condition as in the following :
SELECT ... -- all columns of your queries outer part
(
SELECT s.Date, s.Station, s.worktype, s.tasktype, description as process, ....
FROM source s
INNER JOIN reference r on ( concat(s.worktype,s.tasktype) = r.type )
) D
GROUP BY D.date, D.station, D.worktype, D.accountno;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.