Relatorio Anual.
30/01/2018
0
SELECT
T1.NumNota,
T2.NumOrdem,
T1.CodCliente,
T1.NomeCliente,
T1.DataEmissao,
T1.Cidade,
T1.UF,
T1.CondPagto,
T1.Vendedor,
(T2.ValorTotal + T2.ValorIPI_INT - T2.Desconto) AS ValorItem
FROM
dbo.NotasFiscais T1, dbo.ItemNota T2
WHERE
T1.ObjId = T2.ObjId_Nota
and T1.TipoNota = ''''S''''
and T1.Situacao = ''''N''''
and T2.Fatura = ''''F''''
Enock Junior
Post mais votado
07/02/2018
SELECT NomeCliente, CASE WHEN MES = 1 THEN ValorItem ELSE 0 END ValorItem_janeiro, CASE WHEN MES = 2 THEN ValorItem ELSE 0 END ValorItem_fevereiro, CASE WHEN MES = 3 THEN ValorItem ELSE 0 END ValorItem_marco FROM (SELECT T1.NomeCliente, MONTH(T1.DataEmissao) as Mes, SUM(T2.ValorTotal + T2.ValorIPI_INT - T2.Desconto) AS ValorItem FROM dbo.NotasFiscais T1 inner join dbo.ItemNota T2 ON T1.ObjId = T2.ObjId_Nota WHERE T1.TipoNota = 'S' and T1.Situacao = 'N' and T2.Fatura = 'F' and T1.DataEmissao >= 'DataInicial' and T1.DataEmissao <= 'DataFinal' group by T1.NomeCliente, MONTH(T1.DataEmissao)) as Teste group by NomeCliente
Douglas Sousa
Mais Posts
01/02/2018
Jerson Boer
SELECT T1.NomeCliente, MONTH(T1.DataEmissao) as Mes, SUM(T2.ValorTotal + T2.ValorIPI_INT - T2.Desconto)) AS ValorItem FROM dbo.NotasFiscais T1 inner join dbo.ItemNota T2 ON T1.ObjId = T2.ObjId_Nota WHERE T1.TipoNota = 'S' and T1.Situacao = 'N' and T2.Fatura = 'F' and T1.DataEmissao >= 'DataInicial' and T1.DataEmissao <= 'DataFinal' group by T1.NomeCliente, MONTH(T1.DataEmissao)
02/02/2018
Enock Junior
03/02/2018
Douglas Sousa
Tente dessa forma amigo veja se lhe atende ai é só seguir o padrão para os demais meses, Abraço!
SELECT NomeCliente, CASE WHEN MES = 1 THEN ValorItem ELSE 0 END ValorItem_janeiro, CASE WHEN MES = 2 THEN ValorItem ELSE 0 END ValorItem_fevereiro, CASE WHEN MES = 3 THEN ValorItem ELSE 0 END ValorItem_marco FROM (SELECT T1.NomeCliente, MONTH(T1.DataEmissao) as Mes, SUM(T2.ValorTotal + T2.ValorIPI_INT - T2.Desconto)) AS ValorItem FROM dbo.NotasFiscais T1 inner join dbo.ItemNota T2 ON T1.ObjId = T2.ObjId_Nota WHERE T1.TipoNota = 'S' and T1.Situacao = 'N' and T2.Fatura = 'F' and T1.DataEmissao >= 'DataInicial' and T1.DataEmissao <= 'DataFinal' group by T1.NomeCliente, MONTH(T1.DataEmissao))
05/02/2018
Enock Junior
Msg 102, Level 15, State 1, Line 29
Incorrect syntax near ')'.
06/02/2018
Douglas Sousa
A ideia e mais ou menos essa porem não tem como eu testar
06/02/2018
Enock Junior
Att
07/02/2018
Jerson Boer
SELECT NomeCliente, CASE WHEN MES = 1 THEN ValorItem ELSE 0 END ValorItem_janeiro, CASE WHEN MES = 2 THEN ValorItem ELSE 0 END ValorItem_fevereiro, CASE WHEN MES = 3 THEN ValorItem ELSE 0 END ValorItem_marco FROM (SELECT T1.NomeCliente, MONTH(T1.DataEmissao) as Mes, SUM(T2.ValorTotal + T2.ValorIPI_INT - T2.Desconto) AS ValorItem FROM dbo.NotasFiscais T1 inner join dbo.ItemNota T2 ON T1.ObjId = T2.ObjId_Nota WHERE T1.TipoNota = 'S' and T1.Situacao = 'N' and T2.Fatura = 'F' and T1.DataEmissao >= 'DataInicial' and T1.DataEmissao <= 'DataFinal' group by T1.NomeCliente, MONTH(T1.DataEmissao))
07/02/2018
Jerson Boer
SELECT NomeCliente, CASE WHEN MES = 1 THEN ValorItem ELSE 0 END ValorItem_janeiro, CASE WHEN MES = 2 THEN ValorItem ELSE 0 END ValorItem_fevereiro, CASE WHEN MES = 3 THEN ValorItem ELSE 0 END ValorItem_marco FROM (SELECT T1.NomeCliente, MONTH(T1.DataEmissao) as Mes, SUM(T2.ValorTotal + T2.ValorIPI_INT - T2.Desconto) AS ValorItem FROM dbo.NotasFiscais T1 inner join dbo.ItemNota T2 ON T1.ObjId = T2.ObjId_Nota WHERE T1.TipoNota = 'S' and T1.Situacao = 'N' and T2.Fatura = 'F' and T1.DataEmissao >= 'DataInicial' and T1.DataEmissao <= 'DataFinal' group by T1.NomeCliente, MONTH(T1.DataEmissao)) as Teste
07/02/2018
Enock Junior
Msg 241, Level 16, State 1, Line 1
Conversion failed when converting datetime from character string. Meu sql é 2005
07/02/2018
Enock Junior
Porem preciso também que traga o nome do cliente nas linhas.
Consegue me ajudar????
Pois esta saindo assim
0.00 0.00 2550.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 167.60 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 660.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 1720.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 560.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 9580.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 615.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 3300.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 820.71 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 419.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 2395.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 820.71 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 2395.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 1320.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 75209.82 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 5040.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 420.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 420.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 125.70 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 380.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 840.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 1260.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 167.60 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 4914.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 3400.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 34980.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 820.71 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 1400.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 4400.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 3750.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 3796.44 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 50620.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 2395.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 335.20 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 280.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 4790.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 6160.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 1271.83 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 4341.12 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 3116.40 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 11700.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 7860.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 1752.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 2340.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 44024.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 7770.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 3019.04 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 25300.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 850.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 780.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 372.11 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 5248.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 1590.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 87.60 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 4122.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 2500.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 219.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 87.60 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 600.40 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 219.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 5310.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 309.15 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 89125.08 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 1060.53 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 418.91 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 23710.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 4335.36 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 81.58 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 1990.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 4353.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 4680.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 2460.50 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 5000.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 840.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 11390.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 519.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 22988.37 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 12833.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 780.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 1387.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 2223.50 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 28060.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 3880.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 0.00 0.00 0.00 49730.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
3628.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
4015.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
139382.50 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
31200.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
234.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
12250.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
1080.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
6120.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
1300.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
13464.56 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
16320.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
4200.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
2413.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
30743.94 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
2940.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
3346.40 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
3204.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
36960.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
1700.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
1905.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
39650.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
26221.90 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
19200.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
623.50 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
25754.33 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
1990.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
4800.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
58900.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
55793.76 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
35750.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
4816.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
13800.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
139861.99 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
12100.25 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
3845.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 482.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 3451.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 10772.96 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 5840.23 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 3850.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
0.00 380.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.
07/02/2018
Jerson Boer
07/02/2018
Enock Junior
CASE WHEN MES = 1 THEN ValorItem ELSE 0 END Janeiro,<br />
CASE WHEN MES = 2 THEN ValorItem ELSE 0 END Fevereiro,<br />
CASE WHEN MES = 3 THEN ValorItem ELSE 0 END Marco,<br />
CASE WHEN MES = 4 THEN ValorItem ELSE 0 END Abril,<br />
CASE WHEN MES = 5 THEN ValorItem ELSE 0 END Maio,<br />
CASE WHEN MES = 6 THEN ValorItem ELSE 0 END Junho,<br />
CASE WHEN MES = 7 THEN ValorItem ELSE 0 END Julho,<br />
CASE WHEN MES = 8 THEN ValorItem ELSE 0 END Agosto,<br />
CASE WHEN MES = 9 THEN ValorItem ELSE 0 END Setembro,<br />
CASE WHEN MES = 10 THEN ValorItem ELSE 0 END Outubro,<br />
CASE WHEN MES = 11 THEN ValorItem ELSE 0 END Novembro,<br />
CASE WHEN MES = 12 THEN ValorItem ELSE 0 END Dezembro<br />
FROM<br />
(SELECT<br />
T1.NomeCliente,<br />
MONTH(T1.DataEmissao) as Mes,<br />
SUM(T2.ValorTotal + T2.ValorIPI_INT - T2.Desconto) AS ValorItem<br />
FROM<br />
dbo.NotasFiscais T1 inner join<br />
dbo.ItemNota T2 ON T1.ObjId = T2.ObjId_Nota<br />
WHERE<br />
T1.TipoNota = ''S'' and<br />
T1.Situacao = ''N'' and<br />
T2.Fatura = ''F'' and<br />
T1.DataEmissao >= ''2017-01-01'' and<br />
T1.DataEmissao <= ''2017-12-31''<br />
group by T1.NomeCliente, MONTH(T1.DataEmissao)) as Teste<br />
<br />
Agora preciso deixar o cliente nas linhas <br />
<br />
Exemplo<br />
jan fev mar abr maio jun julh ago set out nov dez<br />
fulano de tal 0.00 0.00 2550.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Clique aqui para fazer login e interagir na Comunidade :)