Solved

INSERT IMAGES IN MSSQL TABLE

Posted on 2014-01-05
1
430 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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 SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

617 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