Reputation: 739
I need to write a simple SQL script to insert a new line to a table with a varbinary
column that is supposed to hold the content of files. I have tried :
DECLARE @FileContent varbinary(max)
SET @FileContent = SELECT * FROM OPENROWSET (BULK 'pathToFile', SINGLE_BLOB);
INSERT INTO [MyTable] ([Name], [Content])
VALUES ('Dummy', @FileContent)
But it does not compile...
Upvotes: 2
Views: 2700
Reputation: 28751
Enclose in round brackets SELECT * FROM OPENROWSET
DECLARE @FileContent varbinary(max)
SET @FileContent = (SELECT * FROM OPENROWSET (BULK 'pathToFile', SINGLE_BLOB) tmp);
INSERT INTO [MyTable] ([Name], [Content])
VALUES ('Dummy', @FileContent)
Upvotes: 4