How to create a report in Sql Server with information by date

Asked

Viewed 860 times

2

I am created a system for output management, one of my tables stores the output history information, it has the following columns,

IDpedido,
DataDoPedido
CodProduto,
QuantidadeProduto
CustoProduto (preço de custo)
VendaProduto (preço de venda )

how can it be my command sql so that I can display an exit report of goods by date?

I’m programming in C# using Sql Server

  • What information do you want to display and how do you want to display them? we from an example of the desired output

  • Hello, in case I want to display date of output, product , quantity , cost , and sale

2 answers

2


John by what I understood his instruction should be:

Select DataDoPedido, 
       CodProduto,
       SUM(QuantidadeProduto),
       SUM(CustoProduto), 
       SUM(VendaProduto)
from 
teste GROUP BY DataDoPedido, CodProduto

In this example the data would be grouped by date and later by product.

I made an example to make it easier. 1 º I populated a table with the same fields as yours:

inserir a descrição da imagem aqui

When I perform the query I showed the result is:

inserir a descrição da imagem aqui

If it were necessary to select a specific date, simply add the clause 'WHERE'

Select DataDoPedido, 
       CodProduto,
       SUM(QuantidadeProduto),
       SUM(CustoProduto),
       SUM(VendaProduto)
from teste
Where DataDoPedido = '2018-04-20 00:00:00' 
GROUP BY DataDoPedido, CodProduto 
  • Ola Clayton, more and in the scenario where the client puts the date he wants ?

  • In this case, simply put a clause 'WHERE' with the date entered by the user. I adjusted the answer with this example as well. The difference is that in your case the date would not be fixed, it would have to be informed via variable for example, for the SQL statement

1

SELECT DataDoPedido, CodProduto, QuantidadeProduto, CustoProduto, VendaProduto
FROM nome_tabela
ORDER BY DataDoPedido;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.