2

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...

1 Answer 1

4

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)
Sign up to request clarification or add additional context in comments.

2 Comments

how, ok, just brackets... Thanks !
SET @FileContent = (SELECT * FROM OPENROWSET (BULK 'pathToFile', SINGLE_BLOB) x);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.