Posts

Showing posts with the label ms sql

Inserting an image into Image column

Last month I was trying to insert an image(file) directly via sql query into my MS SQL Server database table. I used the following; DECLARE @myImage binary SET @myImage = (SELECT * FROM OPENROWSET(BULK N'F:\porsche.jpg', SINGLE_BLOB) AS i) In this query we can declare a binary variable and set its content to the "porsche.jpg". After this, it will be easy to insert the data via insert query. INSERT INTO [USER] ([UserKey] ,[Icon] VALUES (2, @myImage)