I have a table that has thousands of rows in. I need to check if certain values exists in the table or not.
I want to list all the bar codes I am searching with a flag of true or false returned if there is one.
I have come up with this so far:
SELECT CASE WHEN EXISTS (
WHERE Coulmn in ('a','b', 'c', 'd', 'e', 'f', 'g')
THEN CAST(1 AS BIT)
ELSE CAST(0 AS BIT) END
Coulmn | Exsists
A | True
B | True
C | False
D | True
E | True
F | True
G | True
With the help form above I created a temp table and then implemented one of the soultions shared.
CREATE TABLE #Temp ( Barcode VARCHAR (100) ) INSERT INTO #Temp VALUES (1), (2), (3), (4 ) select barcode, case when exists (select * from CIPKORHHTProductDetails where CIPKORHHTProductDetails.Barcode = #temp.barcode) then 'True' else 'False' end as ExistsStatus from #temp order by ExistsStatus DESC