Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Problem in loading image in a VARBINARY(MAX) field

Author  Topic 

Vasudev
Starting Member

3 Posts

Posted - 2012-05-30 : 11:17:52
Hi, I've loaded SQL Server 2008 Express in my laptop and trying to create a table with a column of VARBINARY(MAX) type. While creating it doesn't give any error. But when I give command "INSERT INTO tablename (column_name) SELECT column_name FROM column_name FROM OPENROWSET(BULK N'path_of_image', SINGLE_BLOB) AS tt", I get "Msg 207, Level 16, State 1, Server MyMcName\SQLEXPRESS, Line 1 Invalid column name 'column_name'. Can anybody pls help in resolving this issue..

Thanks in Anticipation.
Vasudev

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-05-30 : 11:57:37
INSERT INTO tablename (column_name) SELECT column_name FROM column_name FROM OPENROWSET(BULK N'path_of_image', SINGLE_BLOB) AS tt(column_name)
Go to Top of Page

Vasudev
Starting Member

3 Posts

Posted - 2012-05-30 : 21:06:44
quote:
Originally posted by robvolk

INSERT INTO tablename (column_name) SELECT column_name FROM column_name FROM OPENROWSET(BULK N'path_of_image', SINGLE_BLOB) AS tt(column_name)



Hi Robvolk, Thank you very much for the courtesy. But while I think your code should work, I'm facing another problem that my table is having suppose 4 columns including one 'Not Null', Varchar and varbinary(max). Now when I tried with your code I get 'Can not insert the value NULL into column_not_null, table 'database_name.dbo.table_name'; column does not allow nulls. INSERT fails.' Hence can you suggest how can I insert values in all columns in one go AND how can I insert image in a column which is already having values in other columns except the varbinary column.
Thank you in Advance for the help.
Vasudev
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-30 : 21:58:54
for multiple columns use

INSERT INTO tablename (column_name1,columnname2,imagecolumn)
SELECT value1,value2,
(SELECT * FROM OPENROWSET(BULK N'Image Path Here', SINGLE_BLOB)as u)

for latter use just an update like

UPDATE t
SET t.ImageCol= (SELECT * FROM OPENROWSET(BULK N'ImagePathHere', SINGLE_BLOB)as u)
FROM Table
WHERE...


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

Vasudev
Starting Member

3 Posts

Posted - 2012-05-30 : 23:12:32
quote:
Originally posted by visakh16

for multiple columns use

INSERT INTO tablename (column_name1,columnname2,imagecolumn)
SELECT value1,value2,
(SELECT * FROM OPENROWSET(BULK N'Image Path Here', SINGLE_BLOB)as u)

for latter use just an update like

UPDATE t
SET t.ImageCol= (SELECT * FROM OPENROWSET(BULK N'ImagePathHere', SINGLE_BLOB)as u)
FROM Table
WHERE...


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





Hi Visakh,

Thank you very much for the prompt response. I'll try in the evening at home and will update you with the outcome.

Thanks once again to all who're so helpful.
Vasudev
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-05-30 : 23:18:41
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -