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 2000 Forums
 Transact-SQL (2000)
 Select as stored procedure parameter

Author  Topic 

imp_galo
Starting Member

13 Posts

Posted - 2006-01-26 : 06:04:54
Is it possible to use a select as a stored procedure parameter or do I have to use cursor?

For example, I have the following procedure:
UpdateTaskProgress @TaskId int

Is it possible to use something like the code bellow to update all tasks?
EXECUTE UpdateTaskProgress select TaskId from Tasks

Thanks in advance,
Ricardo

Srinika
Master Smack Fu Yak Hacker

1378 Posts

Posted - 2006-01-26 : 08:15:05
Not sure what u r trying to do!!
[Its good if ur requirement is written clearly with some example & the result that u want to achieve]

U can use a stored procedure
- to Update some table / records
- to get the results back for viewing
- to accept parameters and based on that do an update
-- u can pass the complete query (rarely done) as a parameter
-- u can pass the selection criteria where clause (again not much used)
-- u can pass the data to be updated, and data to be used for search


Go to Top of Page

mmarovic
Aged Yak Warrior

518 Posts

Posted - 2006-01-26 : 12:00:01
You can either use cursor or pass list of taskIds varchar value or ... More details are needed.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-01-26 : 20:16:25
Try this
exec master..xp_execresultset N'select ''exec UpdateTaskProgress '' + convert(varchar(10), TaskId) from Tasks', N'<your database name>'

Note : xp_execresultset is undocumented

----------------------------------
'KH'


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-01-27 : 05:44:54
or Run this and copy the result back to Query Analyser and run them as a whole

Select 'EXECUTE UpdateTaskProgress '+cast(TaskId as varchar) from Tasks

Madhivanan

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

- Advertisement -