Solved

Using OPENROWSET twice in one SQL statement

Posted on 2014-03-05
1
353 Views
Last Modified: 2014-03-07
I have two filestream columns in a table, one to hold a full-size photo, the other for a thumbnail image. I want to populate both columns at the same time. At the moment I'm uploading just the photo:

SET @sql = 
'INSERT INTO myTable (Filename, Image) ' +
'SELECT ''' + @Filename + ''' , Photo.* ' + 
'FROM OPENROWSET (BULK ''' + CONVERT(varchar(1000), @Path) + ''', SINGLE_BLOB) Photo'
EXEC sp_executesql @sql	

Open in new window



How do I amend this statement to include the thumbnail file?
0
Comment
Question by:TimHudspith
1 Comment
 
LVL 42

Accepted Solution

by:
EugeneZ earned 500 total points
ID: 39908796
try
INSERT INTO myTable (imgid,imgname,fsImg,tnImg)

select
NEWID(),
'imgname',
bulkcolumn
FROM OPENROWSET(BULK 'C:\img\fsphoto.gif', SINGLE_BLOB) AS A,
bulkcolumn
FROM OPENROWSET(BULK 'C:\img\TNphoto.gif', SINGLE_BLOB) AS B,
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
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.

746 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

10 Experts available now in Live!

Get 1:1 Help Now