2

I've a table cSc_Role with a column RoleSettings. RoleSettings is datatype image. The Content is something like this: 0x504B030414000000080000000000E637CA2A4

Now I need to update this column for one row. Like this:

UPDATE cSc_Role
SET RoleSettings = '0x343240000000000E637CA2A430500'
WHERE Naming = 'User X'

But with binary data it seems like this is not possible to do it with a string. The other option is, I can provide the image in a temporary .bak file. And then do an INSERT INTO. But with this solution I've read it is only possible to insert a complete row and not only a column. Or can I insert only a column with insert?

How can I update or insert one image-column in a table? Thanks in advance.

4 Answers 4

2

Try to use convert to varbinary:

UPDATE cSc_Role
SET RoleSettings = convert(VARBINARY(MAX),'0x343240000000000E637CA2A430500')
WHERE Naming = 'User X'
Sign up to request clarification or add additional context in comments.

2 Comments

this works (u just missed an e in convert). And it converts the given string into hex. So, what I want to copy into RoleSettings is the content from another database, where I copied the content into a textfile. So, I think first I need to convert this content into decimal, and then convert it back with update into hex?
@user1673665 I'm not sure but maybe you're right. Try it then you will know :)
1

If above all solution did not work then try to update like below by removing '' in following ,

UPDATE cSc_Role
SET RoleSettings = 0x343240000000000E637CA2A430500
WHERE Naming = 'User X'

Also, avoid using these data types (ntext, text, and image) in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead.

Comments

0

Use a hex-literal, x'34....'

UPDATE cSc_Role
SET RoleSettings = x'343240000000000E637CA2A430500'
WHERE Naming = 'User X'

3 Comments

Thank you for your answer. But when I try this I get error wrong syntax. I put the letter x before the ' and removed the 0x at the beginning.
Which dbms are you using? (My answer is ANSI SQL compliant...)
MS SQL Server Management Studio 2008 R2
0

I had a same problem on project, you need to provide binary data as hex value, not string. This tool can make you UPDATE or INSERT that you need

Binary-file-to-sql-hexstring

It has saved me a lot of man hours.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.