February 23, 2005 at 7:59 pm
I would like some help in the following where the execution results of a stored procedure could be stored in a variable. example
declare @ip varchar(30)
declare @command varchar(100)
declare @data varchar(100)
set @ip = '12.23.200.79'
declare @switch varchar(30)
set @switch = ' |find "Name"'
set @command = 'nslookup ' + @ip + @switch
exec master..xp_cmdshell @command
--I want to pass the results of above exec into say @data to use in an insert like CREATE TABLE #ip
(127.0.0.1 char (100) NULL, ([name] char (100) NULL,)
insert #ip (ip,name) select @ip, @data
Please help
February 23, 2005 at 8:24 pm
You'll need to insert the results from xp_cmdshell into a temp table.
EG:
Create table #xp ( xp_out varchar(255) )
INSERT INTO #XP
EXEC Xp_cmdshell etc...
--------------------
Colt 45 - the original point and click interface
February 24, 2005 at 3:08 pm
In your initial example you just executed the xp_cmdshell procedure but didn't store it anywhere. If you replace that with my suggestion then the results are stored in the temp table. Then it's an easy step to insert data from that temp table and your variable into another temp table.
insert #ip (ip,name) select @ip, xp_out from #xp
If you just want to return the ip and name to the client, then leave out the insert.
--------------------
Colt 45 - the original point and click interface
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply