Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Loop in StoreProcedure

Author  Topic 

dainova
Starting Member

31 Posts

Posted - 2010-01-04 : 04:14:34
Hi,
Being new to sql, I'm facing a task to create some 30+ totals lines from db each of them could be like:
< SELECT SUM(VOLUME) FROM T1 WHERE CUST=CUST01 >
and I need to go thru list of all Customers CUST01 - CUST40 (SELECT DISTINCT CUST FROM T1), is there any way to code this in loop in single SP, and get output in separate files (or line). I don't think that have 40 SPs is a right way.

It's for SQLServer 2003. I also will appreciate opinioins how it could be done on Oracle.

tx
Dai

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-04 : 05:22:59

SELECT CUST,SUM(VOLUME) FROM T1
GROUP BY CUST

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2010-01-04 : 05:41:53
There is no SQL Server 2003, do you mean SQL Server 2000 or 2005 or 2008?
To get this info just run:
select @@version


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

dainova
Starting Member

31 Posts

Posted - 2010-01-04 : 14:07:51
to Webfred: Sorry, it's SQL Server 2000.

to Madhivanan: Tx, Ideally I'll need to put each Totals in separate file, that's why was thinking about some looping.

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-01-05 : 01:15:31
This may help you
http://sqlblogcasts.com/blogs/madhivanan/archive/2009/10/26/script-out-procedures-to-seperate-files.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-01-05 : 03:15:05
quote:
Originally posted by dainova

to Webfred: Sorry, it's SQL Server 2000.

to Madhivanan: Tx, Ideally I'll need to put each Totals in separate file, that's why was thinking about some looping.




so you need each customers total exported to different files? does it need individual info also?
Go to Top of Page
   

- Advertisement -