on 08-22-2011 11:52 PM
Buen día a tod@s!
Estoy trabajando en un Libro Mayor a detalle cuya estructura debe verse así:
Cod. Cta. / Fecha - Nom.Cta. / Nº Asiento ----- Id SAP -- Concepto ----------------------------- SI - Debe ----- Haber - SF
21101 Proveedores Nacionales
01/03/2011 252824 35977 Factura de Proveedores - 21101 50.5656 0.00
01/03/2011 252824 35977 Factura de Proveedores - 25852 5053.56 0.00
Pero la consulta me devuelve este dato:
Cod. Cta. / Fecha - Nom.Cta. / Nº Asiento ----- Id SAP -- Concepto ----------------------------- SI - Debe ----- Haber - SF
01/03/2011 252824 35977 Factura de Proveedores - 21101 50.5656 0.00
01/03/2011 252824 35977 Factura de Proveedores - 25852 5053.56 0.00
21101 Proveedores Nacionales
El código que estoy usando es este:
USE [DEMO_STAR]
GO
/****** Object: StoredProcedure [dbo].[Libro_Diario_Mayor_CS] Script Date: 22/08/2011 08:41:00 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <AlexMeza>
/*LIBRO DIARIO MAYOR CELULAR STAR S.A. DE C.V.*/
/*CURRENT VERSION 1.2*/
/*LAST MODIFY 22/08/2011 08:41:00*/
-- =============================================
ALTER PROCEDURE [dbo].[Libro_Diario_Mayor_CS]
-- Add the parameters for the stored procedure here
@FechaIni datetime,
@FechaFin datetime,
@FechaAct datetime
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
DECLARE @Libro_Diario_Mayor_CS4 TABLE (
CodCta nvarchar(15),--Contendra Codigo de cuenta en las filas de cuenta a detallar y fecha para el detalle de operaciones
NbreCta nvarchar(100),--nombre de la cuenta en las filas de cuenta a detallar y numero de asiento contable
NumDoc nvarchar(100),--numero de documento generado en SAP a la factura si fuere el caso
Concepto nvarchar(100),--descripcion del tipo de operacion realizada
NumRefCta nvarchar(15),--unicamente para referenciar el orden de las cuentas
SldoInicial numeric(19,6),
Debe numeric(19,6),
Haber numeric(19,6),
SldoFinal numeric(19,6),
Acumulado numeric(19,6)
);
INSERT INTO @Libro_Diario_Mayor_CS4
SELECT T0.[AcctCode],
T0.[AcctName],
'',
'',
T0.[AcctCode],
0.00,
0.00,
0.00,
0.00,
0.00
FROM OACT T0
LEFT JOIN JDT1 T1 ON T0.[AcctCode] = T1.[Account]
WHERE T0.[Levels] > 2
GROUP BY T0.[AcctCode],
T0.[AcctName]
INSERT INTO @Libro_Diario_Mayor_CS4
SELECT CONVERT(VARCHAR,T1.[Refdate],103),
T0.[Number],
T0.[BaseRef],
T1.[LineMemo],
T1.[Account],
0.00,
T1.[Debit],
0.00,
0.00,
0.00
FROM OJDT T0
LEFT JOIN JDT1 T1 ON T0.[TransId] = T1.[TransId]
LEFT JOIN OACT T2 ON T1.[Account] = T2.[AcctCode]
WHERE T2.[Levels] > 3 AND T2.[GroupMask] = 2 AND T0.[RefDate] >= @FechaIni AND T0.[RefDate] <= @FechaFin
GROUP BY T1.[RefDate],
T1.[Account],
T0.[BaseRef],
T0.[Number],
T1.[LineMemo],
T1.[Debit]
SELECT A.[CodCta] 'Codigo de Cuenta',
A.[NbreCta] 'Cuentas Padre',
A.[NumDoc],
A.[Concepto] 'Cargo',
A.[SldoInicial] 'Saldo Final',
A.[Debe],
A.[Haber],
A.[SldoFinal] 'Acumulado'
FROM @Libro_Diario_Mayor_CS4 A
GROUP BY A.[CodCta],
A.[NbreCta] ,
A.[NumDoc] ,
A.[Concepto],
A.[NumRefCta],
A.[SldoInicial],
A.[Debe] ,
A.[Haber] ,
A.[SldoFinal]
ORDER BY A.[NumRefCta]
/*========================================================================================================================
========================================================================================================================*/
END
esta, claro, en desarrollo y la primer prueba me arrojo ese problema, a quien me pueda ayudar Gracias!
Alex
Por lo que veo, el problema esta en el campo "cuentas padre" ya que cuando lo oredenas, tienes numeros (que representan las cuentas) y mas abajo tienes el nombre de la cuenta. Al ordenar lo que hara es ordenar por numero y luego por caracteres.
Te sugiero agregar un campo donde vaya solo la cuenta padre, no el nombre de la cuenta y ordenes por ese codigo, no es necesario que lo traigas en el informe, solo es para ordenar el resultado.
Atte.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Alex, no se le entiende a tu post!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
7 | |
6 | |
3 | |
3 | |
3 | |
3 | |
3 | |
3 | |
2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.