Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Totals from a set of dates
Message
From
26/02/2010 17:48:49
Moacyr Zalcman
Independent Consultant
São Paulo, Brazil
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Environment versions
SQL Server:
SQL Server 2005
Application:
Desktop
Miscellaneous
Thread ID:
01451177
Message ID:
01451359
Views:
34
Hi, Borislav

Table HistoricoProduto

id prodid caddate tipo historico
---------- ---------- ----------------------- -------------------- --------------------------------------------------------------------------------------------------------------
[714640] [99608] [ 2010-02-23 17:27:38.000 ] [ Posição] [ Colocação em Venda (est=34)]
714641 101899 2010-02-23 17:27:38.000 Posição Colocação em Venda (est=60)
714638 101226 2010-02-23 17:20:03.000 Posição Colocação em Venda (est=60)
714639 101234 2010-02-23 17:20:03.000 Posição Colocação em Venda (est=60)

From this table I extract for each prodID the max(caddate) filtering certain conditions( at this point the conditions aren't important the point is I extract prodID and caddate)

Table romaneio

id valor caddate
---------- --------------------------------------- ---------- -----------------------
[769291] [2459.06] [ 2010-02-23 16:57:14.000]
769290 3055.14 2010-02-23 16:34:23.000
769289 1064.73 2010-02-23 15:34:03.000
769288 2055.85 2010-02-23 15:29:17.000

For each caddate I extracted in historicoproduto I need sum(valor) from romaneio where romaneio.caddate > historicoproduto.caddate

Result


ProdID Data Sales
---------- ----------------------- ---------------------------------------
[90597] [ 2009-09-09 10:14:00] [ 544645.44]
90808 2009-09-09 10:17:00 29999.87
99492 2010-02-19 09:14:00 3000000
88866 2010-02-11 09:48:00 237654

ProdID was put on sales in Data( date in portuguese) and after this date the amount of sales was Sales

The code I show scan the result from a query in historicoproduto and for each historicoproduto.caddate I calculate the sum of sales.What I'd like to know is if there is a way to do this calculation without using cursor and scanning it;

The udf_TempoDecorridoSegundos calculates the amount of time between the date I pass as a parameter and now.

I hope this clarify what I need and thanks for any help
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform