mardi 2 août 2016

SQL2005: LOOP THE SAME QUERY FOR EVERY ROW OF ANOTHER TABLE

I'm tryng to obtain a loop result for each row in a different table. I need to know which product line, each sales agent, sell in a month. I've the query that show me how to know the total of product lines. I need only to insert inside it, the "CODAGENT" in the where condition, looping trough each agent in the Agents TABLE. So to make an example not in sql language.

-----THIS IS NOT A USEFUL CODE, IT'S ONLY FOR UNDERSTANDING----
For Each Row in Agents TAble Do
Set #CODAGENT = Row 1,2,3,....
Select
-routine for selecting what i need with inside WHERE CODAGENT =  #CODAGENT 
Next Row
-----THIS IS NOT A USEFUL CODE, IT'S ONLY FOR UNDERSTANDING----

Thank you guys

Aucun commentaire:

Enregistrer un commentaire