Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

INSERT IMAGES IN MSSQL TABLE

Posted on 2014-01-05
1
Medium Priority
?
433 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 2000 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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
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.
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.

715 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