Solved

INSERT IMAGES IN MSSQL TABLE

Posted on 2014-01-05
1
417 Views
Last Modified: 2014-01-06
Dear Experts,

I have a code that looks like this:

UPDATE Categories
SET CategoryPicture =
      (SELECT * FROM OPENROWSET(BULK N'C:\Temp\Beverages.jpg', SINGLE_BLOB) AS CategoryImage)
WHERE CategoryID = 1

From my stored procedure, i want to replace 'C:\Temp\Beverages.jpg' with a variable name @x1 so that i can pass @x1 as a paramater each time CategoryID changes.

Please help with necessary codes or alternatives.

Thank you.
0
Comment
Question by:ukconcepts
1 Comment
 
LVL 11

Accepted Solution

by:
Louis01 earned 500 total points
ID: 39758646
DECLARE @SQL varchar(max);
DECLARE @x1 varchar(max) = 'C:\Temp\Beverages.jpg';

SET @SQL = 'UPDATE Categories 
                            SET CategoryPicture = (SELECT BulkColumn FROM OPENROWSET(BULK N''' + @x1 + ''', SINGLE_BLOB) CategoryImage) 
WHERE CategoryID = 1';

EXECUTE (@SQL);

Open in new window

0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now