0

I have a SQL Server 2008 database with a table containing an image column.

Any idea how to write query to insert bin file to the image field?

Thank you in advance!

3

1 Answer 1

1

Totally agree with marc_s.

But your query will be something like this.

INSERT yourtable(ImageColumn)
SELECT image FROM
OPENROWSET(BULK, 'filename.png', SINGLE_BLOB) AS blobtable(image)
Sign up to request clarification or add additional context in comments.

6 Comments

BUT: That is bad practice noramlly as it assumes the file is reachable FROM THE SERVER - not whatever application you run it in. Better: load it in your application and then move it via prameterized query.
@TomTom OK, I fully agree with you, but, maybe, OP wants load files to DB by SSMS in test purpose.
Well, maybe he likes eating Pizza. Irrelevant. SSMS etc. is something he is respsonsible for mentioning, not me for assuming. SImple like that. I assume the 95% of all use cases: an application writing data to the Server, not the 5% edge case.
OK. But this 5% also have the right to life. Question is very concrete and not about best practice and design. And i gave concrete answer.
Yes, and I expect those fringe cases to be named. Not someone making gross statements because somewhere in some cases it makes sense. your approach in normal applications is a reason to send you to HR to talk about incompetence. This answer should not be in a general question.
|

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.