Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Sum Fields in a table
Message
From
12/09/2011 12:05:14
Moacyr Zalcman
Independent Consultant
São Paulo, Brazil
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
Other
Title:
Sum Fields in a table
Environment versions
SQL Server:
SQL Server 2005
Application:
Desktop
Miscellaneous
Thread ID:
01523260
Message ID:
01523260
Views:
84
Hi, people

I have a table named nf with a field dataemissao( date) and a field nfnum and indexed by these fields, and a table named nfitens with foreign Key nfnum from nf table, and two fields vcofins and vpis( numeric values). I need the sum of these fields in a period of time. It's not surprise that the performance of the query that sums these( vPIS and vCOFINS) decrease with the period of time increase.
I can put the sum of vpis and vcofins for every nfnum in the nf table and the problem is solved. But is there any other idea to speed the query?
 SELECT 
 	SUM( Nfitens.vCOFINS) as VCOFINS,
 	SUM( Nfitens.vPIS) as VPIS
 	FROM 
     nf Nf inner join Nfitens on nf.nfnum=nfitens.nfnum
	 WHERE nf.dataemissao  BETWEEN  ?tddatefrom and ?tddateto
Next
Reply
Map
View

Click here to load this message in the networking platform