We help IT Professionals succeed at work.

cursor sql2008 r2

Mortarello
Mortarello used Ask the Experts™
on
Guys,

I'm learning Cursor and did some code feeding a cursor variable using select stament like this

declare MyCursor cursor for (select name from Client )

Is it possible to feed cursor but using Exec command. I would like to retrieve some information from a procedure sp_spacedused.

declare MyCursor cursor for exec sys.sp_spaceused client

Is it possible ?

Tks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Because I Want to work with the result of that procedure sp_spaceused
Commented:
Hi,

You could fill a temporary table with the output from the sp, like

CREATE TABLE #temp (name sysname, rows int, reserved varchar(10), data varchar(10), index_size varchar(10), unused varchar(10) )

INSERT #temp
EXEC sys.sp_spaceused client

declare MyCursor cursor for (select name from #temp)


/peter

Author

Commented:
Thanks Pivar.

Good one