Usuário com melhor resposta
Converter procedure de interbase para Sql server

Pergunta
-
Respostas
-
Alguns pontos que são diferentes:
Bloco de Criação da sua procCREATE PROCEDURE SP_DIVIDA_ATIVA (
PINSCRICAO VARCHAR(14),
DT_CALCULO DATETIME,
PTP_TRI INT)
AS
Vc não precisa criar os parametros de saída. Se existir algum retorno, o SQL Server já te retorna.
Declaração de variáviesDECLARE @vTributo AS INT
DECLARE @VINSCRICAO VARCHAR(14)
DECLARE @VDataVencimento AS DATETIME
DECLARE @VJuros AS Float
-- Declarar todas as variaveis necessariasRetornando valores para uma tabela temporária-- Todos estes dados estarão na sua #tabelaTemporaria
-- # --> Somente esta conexão consegue acessar esta tabela
-- ## --> Todas as conexões conseguem acessar esta tabela
select DT_CAL_DVT ,VL_MES_DVT,VL_MU1_DVT,VL_MU2_DVT,VL_MU3_DVT,TP_UNI_IPT
into #tabelaTemporaria
From ParametroNão utilize IFs e mais IFs, utilize o CASE WHEN-- Seus ELSE IF foram Trocados por CASE WHEN
SELECT CASE WHEN 1=1 THEN
'UM é igual a UM'
WHEN 1=2 THEN
'UM é menor a DOIS'
END as AliasDaColuna
Se não conseguir traduzir algum ponto da sua proc, nos diga onde que está complicado que nós te ajudamos.
Abs,
Todas as Respostas
-
-
Eu tenho uma procedure ja funcionando em Interbase, mas agora estou migrando minha aplicação para Sql Server, com isso tenho que migrar minha procedure tbm, como faço?
A minha procedure é essa:
CREATE PROCEDURE SP_DIVIDA_ATIVA (
PINSCRICAO VARCHAR (14),
DT_CALCULO DATE,
PTP_TRI INTEGER)
RETURNS (
INSCRICAO VARCHAR (14),
ANO INTEGER,
DT_VEN DATE,
VL_ORI NUMERIC (15, 2),
VL_COR NUMERIC (15, 2),
VL_JUR NUMERIC (15, 2),
VL_MUL NUMERIC (15, 2),
VL_TOT NUMERIC (15, 2))
AS
declare variable vTributo Integer;
declare variable vCD_Imp Integer;
declare variable vVl_Div Float;
declare variable vVl_Guia Float;
declare variable VANO Float;
declare variable VINSCRICAO VARCHAR(14);
declare variable vDataCalculo Date;
declare variable vDataVencimento Date;
declare variable VJuros Float;
declare variable VMulta1 Float;
declare variable VMulta2 Float;
declare variable VMulta3 Float;
declare variable VUFM1 Float;
declare variable VUFM2 Float;
declare variable VMES01 Float;
declare variable VMES02 Float;
declare variable VMES03 Float;
declare variable VMES04 Float;
declare variable VMES05 Float;
declare variable VMES06 Float;
declare variable VMES07 Float;
declare variable VMES08 Float;
declare variable VMES09 Float;
declare variable VMES10 Float;
declare variable VMES11 Float;
declare variable VMES12 Float;
declare variable vTP_UNI_IPT Integer;
BEGIN
/* Inicio dos Calculos da Divida Ativa */
select DT_CAL_DVT ,VL_MES_DVT,VL_MU1_DVT,VL_MU2_DVT,VL_MU3_DVT,TP_UNI_IPT From Parametro into :vDataCalculo,:VJuros,:vMulta1,:vMulta2,:vMulta3,:vTP_UNI_IPT;
FOR SELECT D.nr_ins,D.nr_ano,D.DT_VEN,D.TP_TRI ,D.Vl_Div,D.dt_ven
FROM divida_ativa D WHERE (D.NR_INS =INSCRICAO AND D.TP_TRI =
TP_TRI)
Order by D.Tp_Tri, D.Nr_Ins,D.Nr_Ano
into :vInscricao,:vAno,T_VEN,:vTributo,:vVl_Div,:vDataVencimento DO
Begin
/* Correcao Monetaria : Ufm do Ano e Mes em que houve o Vencimento do Imposto*/
Select ANO.VL_01, ANO.VL_02, ANO.VL_03, ANO.VL_04, ANO.VL_05, ANO.VL_06, ANO.VL_07, ANO.VL_08, ANO.VL_09, ANO.VL_10, ANO.VL_11, ANO.VL_12 from ANO_UFM ANO,PARAMETRO PAR
Where CD_UFM = PAR.CD_UFM_DTV
And extract(year from :vDataVencimento) = ANO.NR_ANO into :vMes01,:vMes02,:vMes03,:vMes04,:vMes05,:vMes06,:vMes07,:vMes08,:vMes09,:vMes10,:vMes11,:vMes12;
if (extract(month from :vDataVencimento)=1) then vUFM1 = vMes01;
Else if (extract(month from :vDataVencimento)=2) then vUFM1 = vMes02;
Else if (extract(month from :vDataVencimento)=3) then vUFM1 = vMes03;
Else if (extract(month from :vDataVencimento)=4) then vUFM1 = vMes04;
Else if (extract(month from :vDataVencimento)=5) then vUFM1 = vMes05;
Else if (extract(month from :vDataVencimento)=6) then vUFM1 = vMes06;
Else if (extract(month from :vDataVencimento)=7) then vUFM1 = vMes07;
Else if (extract(month from :vDataVencimento)=8) then vUFM1 = vMes08;
Else if (extract(month from :vDataVencimento)=9) then vUFM1 = vMes09;
Else if (extract(month from :vDataVencimento)=10) then vUFM1 = vMes10;
Else if (extract(month from :vDataVencimento)=11) then vUFM1 = vMes11;
Else if (extract(month from :vDataVencimento)=12) then vUFM1 = vMes12;
/* Correcao Monetaria : Ufm do Ano e Mes da data de Calculo para a Divida Ativa*/
Select ANO.VL_01, ANO.VL_02, ANO.VL_03, ANO.VL_04, ANO.VL_05, ANO.VL_06, ANO.VL_07, ANO.VL_08, ANO.VL_09, ANO.VL_10, ANO.VL_11, ANO.VL_12 from ANO_UFM ANO,PARAMETRO PAR
Where CD_UFM = PAR.CD_UFM_DTV
And extract(year from :vDataCalculo) = ANO.NR_ANO into :vMes01,:vMes02,:vMes03,:vMes04,:vMes05,:vMes06,:vMes07,:vMes08,:vMes09,:vMes10,:vMes11,:vMes12;
if (extract(month from :vDataCalculo)=1) then vUFM2 = vMes01;
Else if (extract(month from :vDataCalculo)=2) then vUFM2 = vMes02;
Else if (extract(month from :vDataCalculo)=3) then vUFM2 = vMes03;
Else if (extract(month from :vDataCalculo)=4) then vUFM2 = vMes04;
Else if (extract(month from :vDataCalculo)=5) then vUFM2 = vMes05;
Else if (extract(month from :vDataCalculo)=6) then vUFM2 = vMes06;
Else if (extract(month from :vDataCalculo)=7) then vUFM2 = vMes07;
Else if (extract(month from :vDataCalculo)=8) then vUFM2 = vMes08;
Else if (extract(month from :vDataCalculo)=9) then vUFM2 = vMes09;
Else if (extract(month from :vDataCalculo)=10) then vUFM2 = vMes10;
Else if (extract(month from :vDataCalculo)=11) then vUFM2 = vMes11;
Else if (extract(month from :vDataCalculo)=12) then vUFM2 = vMes12;
Vl_Cor = ((vVl_Div/vUfm1)*vUfm2)-vVl_Div;
if (Vl_Cor is NULL) then
vl_Cor = 0;
/*Calculando Juros da Divida Ativa*/
Vl_Jur = (((vVl_Div+Vl_Cor)/100)*VJuros)*((vDataCalculo - vDataVencimento)/30);
/*Calculando Multas da Divida Ativa*/
if ((vDataCalculo - vDataVencimento)> 60) then
VL_MUL = ((vVl_Div+Vl_Cor)/100)*VMulta3;
Else if (((vDataCalculo - vDataVencimento)<= 60) and ((vDataCalculo - vDataVencimento)>= 31 )) then
VL_MUL = ((vVl_Div+Vl_Cor)/100)*VMulta2;
Else if ((vDataCalculo - vDataVencimento)<=30) then
VL_MUL = ((vVl_Div+Vl_Cor)/100)*VMulta1;
/*-------------------------------------*/
INSCRICAO = vInscricao;
ANO = VANO;
VL_ORI = vVl_div;
VL_TOT = VL_ORI+VL_COR+VL_MUL+VL_JUR;
SUSPEND;
EndEND
Se puderem me ajudar.
Obrigado.
-
-
Alguns pontos que são diferentes:
Bloco de Criação da sua procCREATE PROCEDURE SP_DIVIDA_ATIVA (
PINSCRICAO VARCHAR(14),
DT_CALCULO DATETIME,
PTP_TRI INT)
AS
Vc não precisa criar os parametros de saída. Se existir algum retorno, o SQL Server já te retorna.
Declaração de variáviesDECLARE @vTributo AS INT
DECLARE @VINSCRICAO VARCHAR(14)
DECLARE @VDataVencimento AS DATETIME
DECLARE @VJuros AS Float
-- Declarar todas as variaveis necessariasRetornando valores para uma tabela temporária-- Todos estes dados estarão na sua #tabelaTemporaria
-- # --> Somente esta conexão consegue acessar esta tabela
-- ## --> Todas as conexões conseguem acessar esta tabela
select DT_CAL_DVT ,VL_MES_DVT,VL_MU1_DVT,VL_MU2_DVT,VL_MU3_DVT,TP_UNI_IPT
into #tabelaTemporaria
From ParametroNão utilize IFs e mais IFs, utilize o CASE WHEN-- Seus ELSE IF foram Trocados por CASE WHEN
SELECT CASE WHEN 1=1 THEN
'UM é igual a UM'
WHEN 1=2 THEN
'UM é menor a DOIS'
END as AliasDaColuna
Se não conseguir traduzir algum ponto da sua proc, nos diga onde que está complicado que nós te ajudamos.
Abs,