I have a map as a input and wanted to use that mapping in sql where clause. Example, I have a table data like,
ColA ColB ColC
---------------
A 1 abc
B 2 xyz
C 3 jkf
A 3 asf
B 4 dfa
and I've mapping as {A->1, B->2}
Now I want to fire query like,
SELECT * from TABLE where KEY = map{key}
but I don't know how can I use my map in above query and I don't want call this query multiple times.
I can do it like, for key in map:
select * from table where key = map[key]
but want to do it in one database call. Expected result is
ColA ColB ColC
---------------
A 1 abc
B 2 xyz
Using the map build table valued constructor
select *
from (values ('A',1),('B',2)) tc (Col1A,ColB)
Now you can join the above result with your table
SELECT *
FROM Yourtable Y
JOIN (VALUES ('A',1),
('B',2)) tc (Col1A, ColB)
ON Y.Col1A = Tc.Col1A
AND Y.Col1B = Tc.Col1B