Usuário com melhor resposta
Relatórios

Pergunta
-
Bom dia
Eu criei essa procedure abaixo, agora preciso criar um relatorio. Alguém pode me ajudar ?
Grato,
USE [PHOTOPAO]
GO
/****** Object: StoredProcedure [dbo].[AUDITOR_ENTRADA_SAIDAS] Script Date: 08/16/2012 10:40:11 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[AUDITOR_ENTRADA_SAIDAS]
@MES INT,
@ANO INT
AS
DELETE FROM SIST WHERE MES = @MES
INSERT INTO SIST
select
N.MESCD,N.nfcdfin,SUM(l.NFVLCONT)AS VALOR_TOTAL,l.opefcd
from
SBPN.DBO.LFNFCB n
inner join SBPN.DBO.lfnflh l on l.nfcdseq = n.nfcdseq
inner join SBPN.DBO.lfprod p on l.prodcd = p.prodcd
where n.MESCD = @MES AND n.ANOCD = @ANO and n.NFTPES = 'E'
GROUP BY n.nfcdfin,l.opefcd,N.MESCD
ORDER BY n.nfcdfin
INSERT INTO SIST
select
N.MESCD,n.nfcdfin,SUM(l.NFVLCONT)AS VALOR_TOTAL,l.opefcd
from
SBPN.DBO.lfnfcb n
inner join SBPN.DBO.lfnflh l on l.nfcdseq = n.nfcdseq
inner join SBPN.DBO.lfprod p on l.prodcd = p.prodcd
where n.MESCD = @MES AND n.ANOCD = @ANO and n.NFTPES = 'S'
GROUP BY n.nfcdfin,l.opefcd,N.MESCD
ORDER BY n.nfcdfin
---
SELECT MES,NOTA,SUM(VALOR)AS VALOR,CFOP
INTO #CONT
FROM CONT
WHERE MES = @MES
GROUP BY CFOP,NOTA,MES
DELETE FROM CONT WHERE MES = @MES
INSERT INTO CONT
SELECT MES,NOTA,VALOR,CFOP FROM #CONT
SELECT
Tipo_de_Ocorrência = 'Possível inconsistência detectada na combinação da NOTA_CONT x NOTA_SIST.',
MES,NOTA,VALOR AS VALOR_CONT,CFOP AS CFOP_CONT
From
CONT T1
Where
(not Exists(Select * From SIST T2 Where (T2.NOTA = T1.NOTA) and (T2.VALOR = T1.VALOR) and (T2.CFOP = T1.CFOP))AND MES =@MES)
Union
Select
Tipo_de_Ocorrência = 'Possível inconsistência detectada na combinação da NOTA_SIST x NOTA_CONT',
MES,NOTA,VALOR AS VALOR_SIST,CFOP AS CFOP_SIST
From
SIST T2
Where
(not Exists(Select * From CONT T1 Where (T2.NOTA = T1.NOTA) and (T2.VALOR = T1.VALOR) and (T2.CFOP = T1.CFOP))AND MES =@MES)
order by NOTA
select Situação = 'Possível inconsistência detectada: Inversão de CFOP',
COUNT(*) as QUANTIDADE from (
SELECT
C.nota AS NOTA,c.cfop as CFOP_CONT,S.CFOP AS CFOP_SIST,C.VALOR AS VALOR_CONT,S.VALOR AS VALOR_SIST
FROM CONT C JOIN SIST S ON C.CFOP <> S.CFOP and c.mes = s.mes and C.nota = S.NOTA and C.VALOR = s.VALOR ) as jjjj
UNION
Select Tipo_de_Ocorrência = 'Notas digitadas na Contabilidade,que não foram encontradas no Sistema',COUNT(*)as QUANTIDADE from(
select distinct dif.NOTAS from(
select
MES,NOTA AS NOTAS,VALOR,CFOP from cont as w
where not exists (select * from sist as z WHERE w.nota = z.nota)) AS DIF ) AS CONT
UNION
Select Tipo_de_Ocorrência = 'Notas digitadas no sistema,que não foram encontadas na Contabilidade',COUNT(*)as QUANTIDADE from(
select distinct dif.NOTAS from(
select
MES,NOTA AS NOTAS,VALOR,CFOP from sist as z
where not exists (select * from cont as w WHERE Z.nota = W.nota)) as dif ) as SIST
SELECT
Tipo_de_Ocorrência = 'Possível inconsistência detectada: Inversão de CFOP',
C.nota AS NOTA,c.cfop as CFOP_CONT,S.CFOP AS CFOP_SIST,C.VALOR AS VALOR_CONT,S.VALOR AS VALOR_SIST
FROM CONT C JOIN SIST S ON C.CFOP <> S.CFOP and c.mes = s.mes and C.nota = S.NOTA and C.VALOR = s.VALOR
WHERE C.MES = @MES
select * from (
select
Tipo_de_Ocorrência = 'Detalhamento da inconsistência: NOTA_CONT x NOTA_SIST.',temp.NOTA_CONT,temp.CFOP_CONT,temp.VALOR_CONT ,temp1.NOTA_SIST,temp1.CFOP_SIST ,temp1.VALOR_SIST AS VALOR_SIST,temp.VALOR_CONT - ISNULL(temp1.VALOR_SIST,0)AS DIF_CONTABILIDADE_X_SISTEMA
from
(SELECT
t1.MES,T1.NOTA as NOTA_CONT,T1.CFOP AS CFOP_CONT,T1.VALOR AS VALOR_CONT
From
CONT T1
Where
(not Exists(Select * From SIST T2 Where (T2.NOTA = T1.NOTA) and (T2.VALOR = T1.VALOR)and (T2.CFOP = T1.CFOP))AND MES =@MES)) temp
right join
(Select
t2.MES,T2.NOTA as NOTA_SIST,T2.CFOP AS CFOP_SIST,T2.VALOR AS VALOR_SIST
From
SIST T2
Where
(not Exists(Select * From CONT T1 Where (T2.NOTA = T1.NOTA) and (T2.VALOR = T1.VALOR)and (T2.CFOP = T1.CFOP))AND MES =@MES)) temp1
on temp.NOTA_CONT = temp1.NOTA_SIST ) as llll
where
DIF_CONTABILIDADE_X_SISTEMA <> 0 or DIF_CONTABILIDADE_X_SISTEMA is null
select Situação = 'Possível inconsistência detectada: Notas que tem na Contabilidade, mais não Existe no Sistema',MES,NOTA AS NOTAS,VALOR,CFOP from cont as w
where not exists (select * from sist as z WHERE w.nota = z.nota)
select Situação = 'Possível inconsistência detectada: Notas que tem no Sistema, mais não Existe na Contabilidade',MES,NOTA AS NOTAS,VALOR,CFOP from sist as z
where not exists (select distinct * from cont as w WHERE Z.nota = W.nota)
/*
Select Tipo_de_Ocorrência = 'Notas digitadas na Contabilidade,mais não encontrada no Sistema',COUNT(*)as QUANTIDADE from(
select distinct dif.NOTAS from(
select
MES,NOTA AS NOTAS,VALOR,CFOP from cont as w
where not exists (select * from sist as z WHERE w.nota = z.nota)) AS DIF ) AS CONT
Select Tipo_de_Ocorrência = 'Notas digitadas no sistema,que não foram encontadas na Contabilidade',COUNT(*)as QUANTIDADE from(
select distinct dif.NOTAS from(
select
MES,NOTA AS NOTAS,VALOR,CFOP from sist as z
where not exists (select * from cont as w WHERE Z.nota = W.nota)) as dif ) as SIST
SELECT * FROM (
SELECT Situação = 'Diferenças entre Notas',
C.nota AS NOTA,c.cfop as CFOP_CONT,C.VALOR AS VALOR_CONT,S.CFOP AS CFOP_SIST,S.VALOR AS VALOR_SIST,C.VALOR - ISNULL(S.VALOR,0)AS DIF_CONTABILIDADE_X_SISTEMA
FROM CONT C JOIN SIST S ON C.CFOP = S.CFOP and c.mes = s.mes and C.nota = S.nota )AS TESTE
WHERE DIF_CONTABILIDADE_X_SISTEMA <>0 --and CFOP_SIST is not null
ORDER BY CFOP_CONT,DIF_CONTABILIDADE_X_SISTEMA
SELECT * FROM (
SELECT Situação = 'Diferenças entre Notas',
C.nota AS NOTA,c.cfop as CFOP_CONT,C.VALOR AS VALOR_CONT,S.CFOP AS CFOP_SIST,S.VALOR AS VALOR_SIST,C.VALOR - ISNULL(S.VALOR,0)AS DIF_CONTABILIDADE_X_SISTEMA
FROM CONT C JOIN SIST S ON c.mes = s.mes and C.nota = S.nota and C.NOTA = s.NOTA)AS TESTE
WHERE DIF_CONTABILIDADE_X_SISTEMA <>0
ORDER BY nota,DIF_CONTABILIDADE_X_SISTEMA
select Tipo_de_Ocorrência = 'Tem na Contabilidade, mais não existe no Sistema',MES,NOTA AS NOTAS_QUE_TEM_NA_CONTABILIDADE_MAIS_NAO_EXISTE_SISTEMA,VALOR,CFOP from cont as w
where not exists (select * from sist as z WHERE w.nota = z.nota)
select Tipo_de_Ocorrência = 'Tem no Sistema,mais não existe na Contabilidade',MES,NOTA AS NOTAS_QUE_TEM_NO_SISTEMA_MAIS_NAO_EXISTE_NA_CONTABILIDADE,VALOR,CFOP from sist as z
where not exists (select * from cont as w WHERE Z.nota = W.nota)
*/
SELECT MES,CFOP, CONVERT(NUMERIC(14, 2), SUM(VALOR)) AS VALOR_TOTAL_SISTEMA
FROM SIST
WHERE MES = @MES
GROUP BY CFOP,MES
SELECT MES,CFOP, CONVERT(NUMERIC(14, 2), SUM(VALOR)) AS VALOR_TOTAL_CONTABILIDADE
FROM CONT
WHERE MES = @MES
GROUP BY CFOP,MES
SELECT MES,CFOP, CONVERT(NUMERIC(14, 2), SUM(VALOR)) AS VALOR
INTO #VALOR_TOTAL_CFOP_SIST
FROM SIST
GROUP BY CFOP,MES
SELECT MES,CFOP, CONVERT(NUMERIC(14, 2), SUM(VALOR)) AS VALOR
INTO #VALOR_TOTAL_CFOP_CONT
FROM CONT
GROUP BY CFOP,MES
SELECT C.CFOP,C.VALOR - ISNULL(S.VALOR,0)AS DIF_CONTABILIDADE_X_SISTEMA
FROM #VALOR_TOTAL_CFOP_CONT C LEFT JOIN #VALOR_TOTAL_CFOP_SIST S ON C.CFOP = S.CFOP
DROP TABLE #CONT
DROP TABLE #SIST
DROP TABLE #VALOR_TOTAL_CFOP_CONT
DROP TABLE #VALOR_TOTAL_CFOP_SIST
Respostas
-
Boa tarde,
Quando comecei no SSRS, eu usei de base o próprio tutorial da microsoft, segue link abaixo.
--
- Marcado como Resposta Harley Araujo segunda-feira, 20 de agosto de 2012 12:31
-
Boa tarde,
Quando comecei no SSRS, eu usei de base o próprio tutorial da microsoft, segue link abaixo.
--
Não esqueça de marcar o post como útil caso tenha te ajudado.
- Marcado como Resposta gildo_santos terça-feira, 28 de agosto de 2012 18:31
Todas as Respostas
-
-
-
Boa tarde,
Quando comecei no SSRS, eu usei de base o próprio tutorial da microsoft, segue link abaixo.
--
- Marcado como Resposta Harley Araujo segunda-feira, 20 de agosto de 2012 12:31
-
Boa tarde,
Quando comecei no SSRS, eu usei de base o próprio tutorial da microsoft, segue link abaixo.
--
Não esqueça de marcar o post como útil caso tenha te ajudado.
- Marcado como Resposta gildo_santos terça-feira, 28 de agosto de 2012 18:31