Solved

INSERT IMAGES IN MSSQL TABLE

Posted on 2014-01-05
1
420 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Copy data to New Year 9 31
WSUS Console loosed connectivity to the database. 13 37
Building JSON Results Table FROM DB 9 32
SQL Syntax 6 40
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
When it comes to protecting Oracle Database servers and systems, there are a ton of myths out there. Here are the most common.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

756 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