@lord_gordon i try to make it for you. Please check
CREATE FUNCTION dbo.EsModulacion (@IdArticulo VARCHAR(50))
RETURNS INT
AS
BEGIN
DECLARE @ExistsInArticulo INT
DECLARE @ExistsInEmbalajes INT
-- Check if the IdArticulo exists in 'Articulo' table
SELECT @ExistsInArticulo = CASE WHEN EXISTS (SELECT 1 FROM Articulos WHERE IdArticulo = @IdArticulo) THEN 1 ELSE 0 END
-- Check if the IdArticulo exists in 'Embalajes' table
SELECT @ExistsInEmbalajes = CASE WHEN EXISTS (SELECT 1 FROM Embalajes WHERE IdArticulo = @IdArticulo) THEN 1 ELSE 0 END
-- Return 1 if the IdArticulo exists in both tables, otherwise return 0
RETURN CASE WHEN @ExistsInArticulo = 1 AND @ExistsInEmbalajes = 1 THEN 1 ELSE 0 END
END;
To call above created function
DECLARE @IdArticuloToCheck VARCHAR(50)
SET @IdArticuloToCheck = 'E134565432'
SELECT dbo.EsModulacion(@IdArticuloToCheck) AS Result;
Let me know your feedback.