Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

running dos copy command from select statement Expand / Collapse
Author
Message
Posted Friday, August 17, 2012 5:45 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, October 13, 2014 4:52 PM
Points: 101, Visits: 236
Here is my Query :

--select item_number from item where item_number like '%Test%'

For each item_number i would like to copy a .bmp file from the server and copy to my local drive.

-- copy \\server1\Images\<Item_number>.bmp c:\temp

Is it possible to run the above command in select statement somehow ?
Post #1346491
Posted Friday, August 17, 2012 6:02 AM


SSC Journeyman

SSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC JourneymanSSC Journeyman

Group: General Forum Members
Last Login: Friday, November 14, 2014 9:53 PM
Points: 75, Visits: 444
You may use dynamic query and xp_cmdshell, smth like this:
--be sure you have permissions from DBA, and configured server:
/*
exec sp_configure 'show advanced options', 1
reconfigure with override
exec sp_configure 'xp_cmdshell', 1
reconfigure with override
*/

declare @sql nvarchar(max);
declare @files table (fname sysname);
insert @files values ('1'),('2'),('3');
set @sql = (
select replace('exec sys.xp_cmdshell ''copy \\server1\Images\<Item_number>.bmp c:\temp'';','<Item_number>',fname)
from @files for xml path('')
)
print(@sql);
--exec(@sql);




I am really sorry for my poor gramma. And I hope that value of my answers will outweigh the harm for your eyes.
Blog: http://somewheresomehow.ru
Twitter: @SomewereSomehow
Post #1346494
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse