Hola lista,
tengo un problema en un sp que estoy modificando me da error en la fila 10,
les copio el sp.
Create Procedure L_DETVSS_KardexGeneralValorado1 --
L_DETVSS_KardexGeneralValorado1 '2410290092', '20070101', '20070430'
@PROD_CodProd Char(15), @VALE_FecEmiI Datetime, @VALE_FecEmiF Datetime
As
Declare @SALD_SaldoF Decimal(14,4), @SALD_CostoPromS Decimal(20,10),
@SALD_CostoPromD Decimal(20,10)
Select A.*, E.ENTC_RazonSoc, Coalesce(T.TIPO_Desc1, 'SALDO ANTERIOR') As
TIPO_DescVale, T1.TIPO_DescC As TIPO_DescDocumento,
Case When A.TIPO_CodVale = '009' Or A.TIPO_CodVale = '010' Then
A1.ALMA_Desc1 Else Null End As AlmacenOrigen,
Case When A.TIPO_CodVale = '009' Or A.TIPO_CodVale = '010' Then
A2.ALMA_Desc1 Else Null End As AlmacenDestino,
D1.DIVI_Descripcion, P.PROD_Factor
From (
Select @SALD_SaldoF = SALD_SaldoF, @SALD_CostoPromS = SALD_CostoPromS,
@SALD_CostoPromD = SALD_CostoPromD
From SaldosGeneral
Where PROD_CodProd = @PROD_CodProd And SALD_FecSaldo (Select Max(SALD_FecSaldo) From SaldosGeneral
Where PROD_CodProd = @PROD_CodProd And SALD_FecSaldo < @VALE_FecEmiI)
Select '00' As SUCR_Codigo, '000' As ALMA_Codigo, '-00' As TIPO_CodVale, -1
As VALE_NumVale, IsNull(@SALD_SaldoF, 0) As DVAL_CantIngr,
Convert(Decimal(14,4), 0) As DVAL_CantSalida, Convert(Decimal(20,10), 0) As
DVAL_CostoS, Convert(Decimal(20,10), 0) As DVAL_CostoD,
IsNull(SALD_CostoPromS, 0) As DVAL_CostoPS, IsNull(SALD_CostoPromD, 0) As
DVAL_CostoPD, Convert(Datetime, '19000101') As DVAL_FecConfir,
'' As VALE_TipDoc, '' As VALE_Serie, '' As VALE_NumSunat, '' As
ALMA_CodDestino, '' As VALE_Produccion, Null AS DIVI_Codigo,
'' As ENTC_Codigo, @PROD_CodProd As PROD_CodProd
Union All
Select V.SUCR_Codigo, V.ALMA_Codigo, V.TIPO_CodVale, V.VALE_NumVale,
D.DVAL_CantIngr, D.DVAL_CantSalida, D.DVAL_CostoS, D.DVAL_CostoD,
D.DVAL_CostoPS, D.DVAL_CostoPD, D.DVAL_FecConfir,
Case When V.VALE_TipDoc Is Null And V.VALE_Serie Is Null Then Null When
V.VALE_TipDoc Is Null And V.VALE_Serie Is Not Null Then '003' Else
V.VALE_TipDoc End As VALE_TipDoc,
V.VALE_Serie, V.VALE_NumSunat, V.ALMA_CodDestino,
Case V.TIPO_CodVale When '006' Then V.VALE_Produccion When '011' Then
D.DVAL_Produccion Else Null End As VALE_Produccion,
Case When V.TIPO_CodVale = '005' Or V.TIPO_CodVale = '006' Or
V.TIPO_CodVale = '011' Then V.DIVI_Codigo Else Null End As DIVI_Codigo,
V.ENTC_Codigo, @PROD_CodProd As PROD_CodProd
From Vales V Inner Join DetValesAlm D
On V.SUCR_Codigo = D.SUCR_Codigo And V.ALMA_Codigo = D.ALMA_Codigo And
V.TIPO_TabVale = D.TIPO_TabVale And V.TIPO_CodVale = D.TIPO_CodVale And
V.VALE_NumVale = D.VALE_NumVale
Where V.VALE_FecEmi Between @VALE_FecEmiI And @VALE_FecEmiF And
D.PROD_CodProd = @PROD_CodProd And V.VALE_Estado = 'C')
A Left Join EntComercial E On A.ENTC_Codigo = E.ENTC_Codigo
Left Join Tipos T On A.TIPO_CodVale = T.TIPO_CodTipo And T.TIPO_CodTabla =
'VAL'
Left Join Tipos T1 On A.VALE_TipDoc = T1.TIPO_CodTipo And T1.TIPO_CodTabla
= 'TDO'
Left Join Almacenes A1 On A.ALMA_Codigo = A1.ALMA_Codigo
Left Join Almacenes A2 On A.ALMA_CodDestino = A2.ALMA_Codigo
Left Join Divisiones D1 On A.DIVI_Codigo = D1.DIVI_Codigo
Inner Join Productos P On A.PROD_CodProd = P.PROD_CodProd
Order By A.DVAL_FecConfir,
Case A.TIPO_CodVale When '000' Then 1 When '001' Then 2 When '002' Then 3
When '011' Then 4 When '010' Then 5 When '009' Then 6
When '007' Then 7 When '008' Then 8 When '005' Then 9 When '006' Then 10
When '013' Then 11 When '014' Then 12 Else 13 End,
A.SUCR_Codigo, A.ALMA_Codigo, A.VALE_NumVale
Saludos
Leer las respuestas