SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Problem in loading image in a VARBINARY(MAX) field
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Vasudev
Starting Member

3 Posts

Posted - 05/30/2012 :  11:17:52  Show Profile  Reply with Quote
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

USA
15559 Posts

Posted - 05/30/2012 :  11:57:37  Show Profile  Visit robvolk's Homepage  Reply with Quote
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 - 05/30/2012 :  21:06:44  Show Profile  Reply with Quote
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

India
47173 Posts

Posted - 05/30/2012 :  21:58:54  Show Profile  Reply with Quote
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 - 05/30/2012 :  23:12:32  Show Profile  Reply with Quote
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

India
47173 Posts

Posted - 05/30/2012 :  23:18:41  Show Profile  Reply with Quote
welcome

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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000