EXEMPLO_1212310
Database
Tables
(current)
Columns
Constraints
Relationships
Orphan Tables
Anomalies
Routines
SAUGETCODESPECMATMEDTISS
Parameters
Name
Type
Mode
@PCODCOLIGADA
int
IN
@CODCONVENIO
int
IN
@IDUNIDFAT
int
IN
@PCODITEM
varchar
IN
Definition
CREATE FUNCTION SAUGETCODESPECMATMEDTISS(@PCODCOLIGADA INT, @CODCONVENIO INT, @IDUNIDFAT INT, @PCODITEM VARCHAR(10)) RETURNS VARCHAR(10) BEGIN DECLARE @VCODPADRAOFATURAMENTO INT, @VCODTISS VARCHAR(10), @VCODTUSS VARCHAR(10), @VCODITEM VARCHAR(10), @VQTD INT SET @VCODITEM = @PCODITEM SELECT @VCODPADRAOFATURAMENTO = CODPADRAOFAT FROM SZCONDCONTRAT WHERE CODCOLIGADA = @PCODCOLIGADA AND CODCONVENIO = @CODCONVENIO AND IDUNIDATEND = @IDUNIDFAT; IF (LEN(@VCODITEM) < 8) BEGIN SET @VCODITEM = REPLICATE('0', 8 - LEN(@VCODITEM)) + RTrim(@VCODITEM) END SELECT @VQTD = COUNT(*) FROM SZCODIFESPECMATMED WHERE CODCOLIGADA = @PCODCOLIGADA AND CODPADRAOFAT = @VCODPADRAOFATURAMENTO AND @VCODITEM BETWEEN INI AND FIM; IF (@VQTD > 0) BEGIN SELECT TOP 1 @VCODTISS = CODTISS, @VCODTUSS = CODTUSS FROM SZCODIFESPECMATMED WHERE CODCOLIGADA = @PCODCOLIGADA AND CODPADRAOFAT = @VCODPADRAOFATURAMENTO AND @VCODITEM BETWEEN INI AND FIM IF (@VCODTISS IS NOT NULL) BEGIN SET @VCODITEM = @VCODTISS + @VCODITEM; END END RETURN @VCODITEM; END;