Saturday, August 4, 2012

HOW TO INSERT A PICTURE INTO SQL TABLE (A correlation name must be specified for the bulk rowset in the from clause) - (T-SQL)



This is very simple solution without writting any additional code for front end application:


CREATE TABLE LogoPicsStg(LogoPic varbinary(max))
INSERTINTO LogoPicsStg(LogoPic)
SELECT* FROM
OPENROWSET(BULK N'c:\temp\logo.jpg', SINGLE_BLOB)


/*
OOPS I DIDN'T EXPECT THIS. THE MESSAGE APPEARS:

Msg 491, Level 16, State 1, Line 3
A correlation name must be specified for the bulk rowset in the from clause.
*/


/*
The new column will be needed here:
*/
ALTER TABLE LogoPicsStg
ADD fname nvarchar(255)


INSERT INTO LogoPicsStg(fname, LogoPic)
SELECT'logo', *
FROM OPENROWSET(
BULK N'c:\temp\logo.jpg', SINGLE_BLOB
)LP

And finally, it worked...

Mike C.

1 comment:

  1. I think it was the LP alias you amended the query with that corrected the correlation name error and not the addition of a new column, at least it was for me.

    ReplyDelete