code_junkie

Can EXEC master..xp_cmdshell be used on a set of data?

Nov 13th, 2011
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. USE Northwind
  2.  
  3. DECLARE @name VARCHAR(32)
  4. DECLARE @command VARCHAR(100)
  5.  
  6. DECLARE shell_cursor CURSOR FOR
  7. SELECT LastName FROM Employees
  8.  
  9. OPEN shell_cursor
  10.  
  11. FETCH NEXT FROM shell_cursor INTO @name
  12.  
  13. WHILE @@FETCH_STATUS = 0
  14. BEGIN
  15. SET @command = 'echo ' + @name
  16. EXEC master.dbo.xp_cmdshell @command
  17. FETCH NEXT FROM shell_cursor INTO @name
  18. END
  19.  
  20. CLOSE shell_cursor
  21. DEALLOCATE shell_cursor
  22.  
  23. GO
Add Comment
Please, Sign In to add comment