Está en la página 1de 3

INSERT dbo.

Plan_Contabless(codigo_pc,Descripcion_Cuenta)
VALUES (105, 'OTROS EQUIVALENTES DE EFECTIVO'),
(1051, 'OTROS EQUIVALENTES DE EFECTIVO'),
(106, 'DEP�SITOS EN INSTITUCIONES FINANCIERAS'),
(1061, 'DEP�SITOS DE AHORRO'),
(1062, 'DEP�SITOS A PLAZO'),
(107, 'FONDOS SUJETOS A RESTRICCI�N'),
(1071, 'FONDOS SUJETOS A RESTRICCI�N'),
(11, 'INVERSIONES FINANCIERAS'),
(111, 'INVERSIONES MANTENIDAS PARA NEGOCIACION'),
(1111, 'VALORES EMITIDOS O GARANTIZADOS POR EL ESTADO'),
(11111, 'DEP�SITOS EN INSTITUCIONES FINANCIERAS'),
(11112, 'DEP�SITOS DE AHORRO'),
(1112, 'DEP�SITOS A PLAZO'),
(11121, 'FONDOS SUJETOS A RESTRICCI�N'),
(1071, 'FONDOS SUJETOS A RESTRICCI�N'),
(11, 'INVERSIONES FINANCIERAS'),
(111, 'INVERSIONES MANTENIDAS PARA NEGOCIACION')
GO

/*Lo primero se registra los datos de la empresa o razon social*/


INSERT dbo.Datos_Empresa(Ruc, Periodo, Razon_Social)
VALUES (20102193402, 'enero', ' EMPRESA IDEAL S.A')
GO

INSERT dbo.Datos_Empresa(Ruc, Periodo, Razon_Social)


VALUES (20102193502, 'febrero', 'SOLDADOS')
GO
/*Segundo se regista el libro diario*/
INSERT dbo.LibroDiario(Ruc, Asiento,
Fecha_Operacion,Descripcion_Operacion,Codigo_Libro,
Codigo_Cuenta_Contable,Debe,Haber)
VALUES (20102193402, 1, '01/01/2018','Por la adquision de
poliza',8,182,14830.51,0)
GO
INSERT dbo.LibroDiario(Ruc, Asiento,
Fecha_Operacion,Descripcion_Operacion,Codigo_Libro,
Codigo_Cuenta_Contable,Debe,Haber)
VALUES (20102193402, 1, '01/01/2018','Por la adquision de
poliza',8,40111,2669,0)
GO
INSERT dbo.LibroDiario(Ruc, Asiento,
Fecha_Operacion,Descripcion_Operacion,Codigo_Libro,
Codigo_Cuenta_Contable,Debe,Haber)
VALUES (20102193402, 1, '01/01/2018','Por la adquision de
poliza',8,4212,0,17500.00)
GO
INSERT dbo.LibroDiario(Ruc, Asiento,
Fecha_Operacion,Descripcion_Operacion,Codigo_Libro,
Codigo_Cuenta_Contable,Debe,Haber)
VALUES (20102193402, 2, '02/01/2018','Por la transferencia',8,60912,14830.51,0)

GO
INSERT dbo.LibroDiario(Ruc, Asiento,
Fecha_Operacion,Descripcion_Operacion,Codigo_Libro,
Codigo_Cuenta_Contable,Debe,Haber)
VALUES (20102193402, 2, '02/01/2018','Por la transferencia',8,60912,0,14830.51)
GO

/*SOLDADOS*/
INSERT dbo.LibroDiario(Ruc, Asiento,
Fecha_Operacion,Descripcion_Operacion,Codigo_Libro,
Codigo_Cuenta_Contable,Debe,Haber)
VALUES (20102193502, 1, '01/02/2018','Por la apertura de las
operaciones',11,1011,36500.00,0)
GO
INSERT dbo.LibroDiario(Ruc, Asiento,
Fecha_Operacion,Descripcion_Operacion,Codigo_Libro,
Codigo_Cuenta_Contable,Debe,Haber)
VALUES (20102193502, 2, '02/02/2018','Cta. cte B Nacional
Mn',11,40111,115000,0)
GO
INSERT dbo.LibroDiario(Ruc, Asiento,
Fecha_Operacion,Descripcion_Operacion,Codigo_Libro,
Codigo_Cuenta_Contable,Debe,Haber)
VALUES (20102193502, 3, '03/02/2018','Por la apertura de las
operaciones',11,4212,0,115000.00)
GO
INSERT dbo.LibroDiario(Ruc, Asiento,
Fecha_Operacion,Descripcion_Operacion,Codigo_Libro,
Codigo_Cuenta_Contable,Debe,Haber)
VALUES (20102193502, 4, '04/02/2018','Por la apertura de las
operaciones',8,5011,0,36500.00)
GO

/*Mostrar Total + razon social*/


select de.Razon_Social,sum(Debe) as Total_Debe,sum(Haber) as Total_Haber from
LibroDiario ld inner join Datos_Empresa de on ld.Ruc = de.Ruc
group by de.Razon_Social

select de.Razon_Social,de.Periodo,sum(Debe) as Total_Debe,sum(Haber) as Total_Haber


from LibroDiario ld inner join Datos_Empresa de on ld.Ruc = de.Ruc
group by de.Razon_Social,de.Periodo

/*El mayor de un Periodo*/


SELECT top 1 MAX(Total_Debe) as Mayor, Sumas.Periodo FROM
(select de.Razon_Social,de.Periodo,sum(Debe) as Total_Debe,sum(Haber) as
Total_Haber from LibroDiario ld inner join Datos_Empresa de on ld.Ruc = de.Ruc
group by de.Razon_Social,de.Periodo) AS Sumas
Group by Sumas.Periodo
order by sumas.Periodo desc

/*el mayor*/
SELECT MAX(Total_Debe) as Mayor FROM
(select de.Razon_Social,de.Periodo,sum(Debe) as Total_Debe,sum(Haber) as
Total_Haber from LibroDiario ld inner join Datos_Empresa de on ld.Ruc = de.Ruc
group by de.Razon_Social,de.Periodo) AS Sumas

/*Mostrar todos el libro diario*/


select * from LibroDiario

/*Mostrar el libo diario y los datos de la empresa */


select
de.Ruc,de.Periodo,de.Razon_Social,ld.Asiento,ld.Fecha_Operacion,ld.Descripcion_Oper
acion,ld.Codigo_Libro,ld.Codigo_Cuenta_Contable,pc.Descripcion_Cuenta,ld.Debe,ld.Ha
ber
from LibroDiario ld inner join Datos_Empresa de on ld.Ruc = de.Ruc inner join
Plan_Contabless pc on ld.Codigo_Cuenta_Contable=pc.codigo_pc

/*actualizar*/
UPDATE dbo.Products
SET ProductName = 'Flat Head Screwdriver'
WHERE ProductID = 50
GO

/*eliminar*/
delete LibroDiario where Asiento='';

/*si hay repetidos*/


select codigo_pc,count(*)
from Plan_Contabless
group by codigo_pc
having count(*)>1;

También podría gustarte