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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Is This possible?

Author  Topic 

duleepnagahawatte
Starting Member

16 Posts

Posted - 2008-01-03 : 04:10:39
I want to select parameter values from a select statement and then pass those values to a stored procedure, so the 2nd stored procedure will execute per value.
EX - 1st select statement will select 100 account numbers. and then they will pass to a 2nd stored procedure which will be executed per account number and produce results (say account details)
So the 2nd procedure will be executed 100 times and will produce 100 lines on the result pain.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-03 : 04:36:11
Try this:-
DECLARE TABLE @Temp
(
AccntNo int
)

INSERT INTO @Temp
SELECT 1000 UNION ALL
SELECT 1050....

DECLARE @ID int

SELECT @ID = MIN(AccntNo)
FROM @Table

WHILE @ID IS NOT NULL
BEGIN
EXEC SPName @Param=@ID
SELECT @ID=MIN(AccntNo)
FROM @Table
WHERE AccntNo>@ID
END
Go to Top of Page

duleepnagahawatte
Starting Member

16 Posts

Posted - 2008-01-03 : 04:44:30
Only problem is that the accntNo is a "varchar", how can i get over that problem.
thanks
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-03 : 04:54:34
quote:
Originally posted by duleepnagahawatte

Only problem is that the accntNo is a "varchar", how can i get over that problem.
thanks


The above example would work for varchar datatype as well

Madhivanan

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

duleepnagahawatte
Starting Member

16 Posts

Posted - 2008-01-03 : 07:19:11
Thank you Both. it works like a dream
Go to Top of Page
   

- Advertisement -