I have to perform a validation on a trigger in sql server the rule is: if cnpj is! = 0 and does not exist in another continue record;
But cnpj can come with 0 or 000 or 0000000 or 00, which would be the same ...
I am currently doing the validation below but they asked me to change the validation! = 0 to something more "elegant", does anyone have any idea how I can do this?
IF 0 != CONVERT(bigint,(SELECT CGC_CPF FROM inserted))
BEGIN
if EXISTS(SELECT * FROM CADASTRO_CLI_FOR A
LEFT JOIN FILIAIS B ON A.COD_CLIFOR=B.COD_FILIAL
WHERE A.CGC_CPF=@CNPJ
AND B.INDICA_ARMAZEM =0)
begin
select @errno = 30002,
@errmsg = 'Impossível Incluir #FORNECEDORES #porque CNPJ #ja existe.'
goto error
end
end
return