filmov
tv
T-SQL: Files import and export using T-SQL for SQL Server

Показать описание
DECLARE @FOLDER as nvarchar(200)
DECLARE @FILE as nvarchar(200)
DECLARE @SQL as nvarchar(200)
CREATE TABLE MyPictures (
ID int,
Folder nvarchar (200),
FName nvarchar (200),
Img varbinary (max)
)
INSERT INTO MyPictures
SET @FOLDER = 'C:\!all\IDEA_A\2 images\'
SET @FILE = 'SQL_JOINS.jpg'
SET @SQL= ' INSERT INTO MyPictures
SELECT *
FROM MyPictures
--DROP TABLE MyPictures
-------------------------------------------------------------------------
--sp_configure 'show advanced options', 1;
--GO
--RECONFIGURE;
--GO
--sp_configure 'Ole Automation Procedures', 1;
--GO
--RECONFIGURE;
--GO
---------------------------------------------
DECLARE @OUTPUT_FOLDER_FILE as nvarchar(200)
DECLARE @INIT int
DECLARE @DATA varbinary(max)
SELECT
@OUTPUT_FOLDER_FILE = [Folder] + 'out_' + [FName],
@DATA=Img
FROM MyPictures
Where ID=1
EXEC sp_OACreate 'ADODB.Stream', @INIT OUTPUT; -- An instace created
EXEC sp_OASetProperty @INIT, 'Type', 1;
EXEC sp_OAMethod @INIT, 'Open'; -- Calling a method
EXEC sp_OAMethod @INIT, 'Write', NULL, @DATA; -- Calling a method
EXEC sp_OAMethod @INIT, 'SaveToFile', NULL, @OUTPUT_FOLDER_FILE, 2; -- Calling a method
EXEC sp_OAMethod @INIT, 'Close'; -- Calling a method
EXEC sp_OADestroy @INIT; -- Closed the resources
-------------------------------------------------------------------------
DROP TABLE MyPictures
DECLARE @FILE as nvarchar(200)
DECLARE @SQL as nvarchar(200)
CREATE TABLE MyPictures (
ID int,
Folder nvarchar (200),
FName nvarchar (200),
Img varbinary (max)
)
INSERT INTO MyPictures
SET @FOLDER = 'C:\!all\IDEA_A\2 images\'
SET @FILE = 'SQL_JOINS.jpg'
SET @SQL= ' INSERT INTO MyPictures
SELECT *
FROM MyPictures
--DROP TABLE MyPictures
-------------------------------------------------------------------------
--sp_configure 'show advanced options', 1;
--GO
--RECONFIGURE;
--GO
--sp_configure 'Ole Automation Procedures', 1;
--GO
--RECONFIGURE;
--GO
---------------------------------------------
DECLARE @OUTPUT_FOLDER_FILE as nvarchar(200)
DECLARE @INIT int
DECLARE @DATA varbinary(max)
SELECT
@OUTPUT_FOLDER_FILE = [Folder] + 'out_' + [FName],
@DATA=Img
FROM MyPictures
Where ID=1
EXEC sp_OACreate 'ADODB.Stream', @INIT OUTPUT; -- An instace created
EXEC sp_OASetProperty @INIT, 'Type', 1;
EXEC sp_OAMethod @INIT, 'Open'; -- Calling a method
EXEC sp_OAMethod @INIT, 'Write', NULL, @DATA; -- Calling a method
EXEC sp_OAMethod @INIT, 'SaveToFile', NULL, @OUTPUT_FOLDER_FILE, 2; -- Calling a method
EXEC sp_OAMethod @INIT, 'Close'; -- Calling a method
EXEC sp_OADestroy @INIT; -- Closed the resources
-------------------------------------------------------------------------
DROP TABLE MyPictures
Комментарии