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)
 Inserting the result of a stored procedure.

Author  Topic 

fireali
Starting Member

2 Posts

Posted - 2005-06-02 : 10:58:00
hi every one!
I wanna update a field by the return result of a stored procedure.
for example:
UPDATE table1 SET field1=(EXEC xp_cmdshell 'dir');

and then filed1 contains the list of directories.

is it possible? how?

nathans
Aged Yak Warrior

938 Posts

Posted - 2005-06-02 : 11:59:05
Since xp_cmdshell opens its own batch you'll have to use a temp table within its scope. Once you have your result in a temp you can update your existing table with the value.

Something like:

-- temp to hold xp_cmdshell output
create table #deez (value varchar(8000))

-- insert output into temp
insert into #deez
exec master..xp_cmdshell 'dir'

-- return result
select * from #deez

-- drop temp
drop table #deez


Nathan
Go to Top of Page
   

- Advertisement -