update name_surname_dictionary set name=upper("helen") where seq='1';
I have a problem . I wanna make this upper like this;
result:"HELEN"
try this
update name_surname_dictionary set name=upper('"helen"') where seq='1';
And don't forget to make a commit to Your statement.
Related
I have an API that takes a PATCH request with one or more parameters and build a query string that looks like this
UPDATE ${table} SET ${param1}${param2}${param3} WHERE id=${id}
problem is if I place commas inside params or in the final query, a request with a single parameter breaks the query
UPDATE ${table} SET ${param1}, WHERE id=${id}
or
UPDATE ${table} SET ${param1},, WHERE id=${id}
how do I remove commas before WHERE?
You could join all the params together, but make sure that the input is sanitized for sql injection. Assuming they're already in a list like
params = [param1, param2, param3];
paramsStr = params.join(", ");
example:
["abc='def'", "xyz=123"].join(',')
#outputs:
'abc=\'def\',xyz=123'
And then use the paramsStr in your query template. With this simple trick you avoid having to deal with trailing / leading commas
UPDATE ${table} SET ${paramsStr} WHERE id=${id}
I have the following line of code.
UPDATE account
SET BlockMessage='$BlockMessage', SET BlockAdmin='$AdminUsername', Status=2
WHERE ID='$ID'
As you can see in trying to set a "BlockMessage, BlockAdmin and Status" in 1 single query. The Infomation is correctly displayed if I echo the 3 individual Variables. however, when running the SQL String it only updates the Block Message row.
Any Ideas?
You have an extra SET. Update should be something like this:
UPDATE account
SET
BlockMessage='$BlockMessage',
BlockAdmin='$AdminUsername',
Status=2
WHERE ID='$ID'
You need use the keyword SET only once like
SET BlockMessage='$BlockMessage',
BlockAdmin='$AdminUsername',
Status=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.
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.
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 a weird problem, when i use the query on phpmyadmin, it works. but when i use using a php script it returns an error.
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in
I tried to troubleshoot and discovered that the problem lies with the set statement.
this is my example code.
$sql = 'set #rank=0; select * from user;';
Please help somebody.
First Run
$sql = set #rank=0;
it will store value of rank
then run:
select * from user;
In sort you need to run both queries separately .
set statement stores values. that can be used by next executing query,
like code below :
$sql ="SET #id:=0";
$Executives=$DB->exec($sql);
$sql = "SELECT #id:=#id+1 as id,pes.* FROM profile_executive_summary as pes where profile_id=".$pid;
$Executives=$DB->fetchAssoc($sql);
See what mysql_error returns after you run mysql_query('...'). That might help. In general, mysql_query only permits one query. You can't separate them by newlines or semicolons. mysqli will do it for you though.