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.
Try to use convert to varbinary:
UPDATE cSc_Role
SET RoleSettings = convert(VARBINARY(MAX),'0x343240000000000E637CA2A430500')
WHERE Naming = 'User X'
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.
Use a hex-literal, x'34....'
UPDATE cSc_Role
SET RoleSettings = x'343240000000000E637CA2A430500'
WHERE Naming = 'User X'
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.
Related
I have one tag in my table having clobe xml data like as below:
I need to update this value to 400. I am doing it as below. But its not updating. Please help.
UPDATE XYZ
SET request_xml = UPDATEXML(xmltype(request_xml),
'Parameters/Parameter[#Name="ABC"]/#Value', 400,'xmlns:n0="http://www.iQWE.com/LKJ"').getClobVal()
where transaction_id = '2017051907471800000000187725';
Your XPath doesn't make much sense. You are looking for a node called Parameter with an attribute called Name, where that attribute value is 'MaxLatenessAllowed'. There is nothing like that in your XMl document.
You can supply the full path to the node you want to change, including namespace info:
UPDATE dfxha_catchup_queue
SET request_xml = UPDATEXML(xmltype(request_xml),
'/n0:CreateOrder/n0:SalesOrders/n0:SalesOrder/n0:SalesOrderLines/n0:SalesOrderLine/n0:MaxLatenessAllowed/#Value',
400,
'xmlns:n0="http://www.i2.com/DFX"').getClobVal()
where transaction_id = '2017051907471800000000187725';
Or to shorten that you can look for that node name anywhere, if that's safe in your schema:
UPDATE dfxha_catchup_queue
SET request_xml = UPDATEXML(xmltype(request_xml),
'//n0:MaxLatenessAllowed/#Value',
400,
'xmlns:n0="http://www.i2.com/DFX"').getClobVal()
where transaction_id = '2017051907471800000000187725';
The updateXML() function is deprecated, so you might want to investigate other ways of achieving this.
update users
set users.przetwarzanie = historia_panel.zmiana_z
from historia_panel
where
users.user_number like historia_panel.user_number and
historia_panel.zmienna_zmieniana like '%przetwarzanie%' and
historia_panel.przyczyna like '%użytkownika%';
And the error is:
The error that is in console:
ERROR: column "users" of relation "users" does not exist
LINE 2: set users.przetwarzanie = historia_panel.zmiana_z
In this query i want to update users table with values from historia_panel table with specified conditions. I tried many different ways but none of examples that i found on the internet works.
Actualy i have no idea what I'am doing wrong...
The error would suggest that you aren't allowed to qualify the column names in the set clause; and indeed you shouldn't need to since you already said update users
Whether that's the only problem I can't say at a quick glance, but that is what the error message is telling you; so try changing set users.przetwarzanie = historia_panel.zmiana_z to just set przetwarzanie = historia_panel.zmiana_z and see what you get
The problem was with incompatible typles between two columns from different tables. I added line set przetwarzanie = historia_panel.zmiana_z::int and now it works.
I've exported my AD into CSV and pumped it into SQL, the goal is to modify some fields and import it back into AD.
I've done every field I need to do except one, the proxyAddress field.
My data looks like this:
proxyAddresses
sip:john.smiths#email.com;SMTP:john.smith#email.com
sip:james.jones#email.com;SMTP:james.jones#email.com;notes:james.jones/EMAIL/
etc...
I'm trying to change the sip: values, but as they're all different username, and have SMTP included, I'm struggling with the SQL LIKE command.
I need to data to look like this:
proxyAddresses
sip:john.smiths#newemail.com;SMTP:john.smith#email.com
sip:james.jones#newemail.com;SMTP:james.jones#email.com;notes:james.jones/EMAIL/
Changing the sip: value, but leaving the rest as they are.
Any help would be appreciated.
We don't know the tables definition nor the mapping between new and old values, so just for the start something like this:
declare #e varchar(1000) = 'sip:james.jones#email.com;SMTP:james.jones#email.com;notes:james.jones/EMAIL/'
declare #newEmail varchar(126) = 'james.jones#newemail.com'
select stuff(#e, charindex(':', #e)+1, charindex(';', #e)-charindex(':', #e)-1, #newEmail)
I use db.insert() to insert data to database, the code is something like this,
db.insert('categories', name=cate_name, description=desc, _test=True)
but it doesn't work, the data can't not be found in table 'categories' after the code is execute, and no exceptions by the way.
Anybody know why this happened?
_Test variable stands for debug purposes.
It lets you get SQL statement instead of executing one.
It means that your command
result = db.insert('categories', name=cate_name, description=desc, _test=True)
will not execute anything on your DB. It will only return a string:
"INSERT INTO categories (name, description) VALUES ('cate_name value', 'desc value')"
If you want to make a real query, you need to remove it:
db.insert('categories', name=cate_name, description=desc)
It should work.
remove _test=True or set _test=False
i have created the udf to strip HTML from sql fields from here:
link text
i am trying to run an update on my table where the defects_from_oracle.Description field has html
my sql is:
update defects_from_oracle
set Description = udf_StripHTML(Description)
where did i go wrong?
i get error:
'udf_StripHTML' is not a recognized
built-in function name.
you missed the dbo. prefex
update defects_from_oracle
set Description = dbo.udf_StripHTML(Description)