0
I created a cursor that shows the date of sale and the total sold value of the day. Follow the code:
declare cursorteste cursor
local forward_only
for select data_venda, sum(valor_unitario) as valor_unitario from venda v, produtoVenda pv
where v.id_venda = pv.id_venda
group by data_venda
open cursorteste
declare @data_venda date, @total decimal(10,2)
fetch cursorteste into @data_venda, @total
while @@FETCH_STATUS = 0
begin
select @data_venda as data_venda, @total as _total
fetch next from cursorteste into @data_venda, @total
end
close cursorteste
deallocate cursorteste
So far so good, the problem comes now..
Now from that cursor, I need to create a temporary table that has the date of sale, the total value sold on the day and the situation of the day. For example:
Minor - means that the current day’s sales were lower than the previous day’s sales
Normal - means that the current day’s sales were equal to the previous day’s sales
Greater - means that the current day’s sales were higher than the previous day’s sales
I know that to create temporary tables I need to use #table_temporaria. I’ve looked through several blogs and Microsoft documentation, and I couldn’t locate anything about it or I couldn’t express myself right about what I was looking for.
How do I create this temporary table from this cursor? How do I create this current day situation condition, based on the previous day?
If anyone can share with me. Thanks guys!!