Show message if IN record does not exist

0
Hello, can someone help me with the following type of query in firebird, so I want to put several numbers of cpf in the IN of a query and if the cpf exists in the table show the data, but if it does not exist show a column indicating that does not exist in the table.

Exemplo: 
Select * from trabalhador where cpf in ('11111111111','22222222222','33333333333','44444444444','55555555555')

Na tabela no existe os três primeiros CPF então o resultado seria 

11111111111 Ana 
22222222222 Carla 
33333333333 Maria 
44444444444 CPF NÃO EXISTE 
55555555555 CPF NÃO EXISTE
    
asked by anonymous 11.06.2018 / 21:46

1 answer

1

Try something like this:

DECLARE @TAB TABLE (
cpf NVARCHAR(255)
)

INSERT INTO @TAB
SELECT '11111111111'
UNION ALL
SELECT '22222222222'
UNION ALL
SELECT '33333333333'
UNION ALL
SELECT '44444444444'
UNION ALL
SELECT '55555555555'

Select T.*, ISNULL(C.cpf, 'NÃO EXISTE') from trabalhador T
RIGHT OUTER JOIN @TAB C
ON T.cpf = C.cpf
    
11.06.2018 / 21:52