I\'m using Microsoft Sql server 2012 as DBMS, there I have my database which is containing informations about football players. Each player has a photography, a
try the following query:
EXEC sp_configure 'show advanced options', 1
GO
RECONFIGURE
GO
EXEC sp_configure 'xp_cmdshell', 1
GO
RECONFIGURE
GO
EXEC master..xp_cmdshell 'mkdir C:\ImagesFromSql'
DECLARE @ID as int
DECLARE @SQL as varchar(4000)
DECLARE csr CURSOR FOR SELECT ID FROM [FootballTeam].[dbo].[Players]
OPEN csr
FETCH NEXT FROM csr INTO @ID
WHILE @@FETCH_STATUS = 0
BEGIN
SET @SQL = 'BCP "SELECT Photo FROM [FootballTeam].[dbo].[Players] WHERE ID = "' + CAST(@ID as varchar(10)) + ' queryout "C:\ImagesFromSql\' + CAST(@ID as varchar(10)) + '.jpg" -T -N'
EXEC master..xp_cmdshell @SQL
FETCH NEXT FROM csr INTO @ID
END
CLOSE csr
DEALLOCATE csr