We know that n1ql comes with syntax sugar like :
#{#n1ql.selectEntity} where #{#n1ql.filter} and fname = "abc".
How do we write a syntax sugar for update statement?
update student set lname="john" where userId="101";
I tried this but does not work
#{#n1ql.update} set lname="john" where #{#n1ql.filter} and fname = "smith"
Related
I intend to do:
EXECUTE('UPDATE tableA SET campaignkey = ''20170101'' where storekey = 16
and campaignkey LIKE ''%,%''') at MYLINKEDSERVER
but I get the error that:
You have an error in your SQL syntax; [...] for the right syntax to use near 'where storekey = 16 and campaignkey LIKE '%,%''
Does anyone have any idea what is wrong? To me it seems like I might have one ' too many on my LIKE statement, but I have Always used '' to indicate a non-numeric value. I don't want to fiddle with this to prevent updating far too many values on this server.
campaignkey is non-numeric (I Believe varchar) and storekey is integer.
Edit
I must not use OPENQUERY() because it is not set up correctly, and this is a urgent update.
Edit 2
Seems like it is because of apostrophes 's in the EXECUTE statement.
When I conduct:
select * from openquery(linkedserver,'Select * from tableA where storekey = 16
and campaignkey = ''20170826,151''')
it works, but when using:
EXECUTE('Select * from tableA where storekey = 16
and campaignkey = ''20170826,151''') at linkedserver
I get the error that I need to check the manual by the where clause. From googling it appears however that the correct syntax in fact is:
EXECUTE('UPDATE TableX SET StringVar = ''stringValue'' WHERE intVar = 3
AND stringVar = ''xxxxx''') AT LinkedServer
I don't know why this won't work for me.. I have tried many combinations of '', '" etc.
What about this one?
update openquery(linkedserver,'Select * from tableA where storekey = 16
and campaignkey = ''20170826,151''')
set campaignkey = '20170101'
I tried running this sql
UPDATE table
SET read = 1
WHERE col1_id = 2
AND col3_id = 1;
and it return an error (error in your sql syntax)
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'read = 1 WHERE team_notification_id = 2 AND listener_id = 1' at line 1
But when I used thesame WHERE and AND :), in a SELECT statement no error was returned.
SELECT *
FROM read
WHERE col1_id = 2
AND col3_id = 1
please what did I do wrong, I am no seeing it.
After keyword UPDATE there should be a table name. If your table has actually name table (that's a bit strange) you should escape it to let MySQL know it's not a keyword "table" but actual table name.
The same thing is about read.
Both table and read are MySQL keywords (the full list is here http://dev.mysql.com/doc/refman/5.7/en/keywords.html) so if it's your actual table and column names then you should escape it.
Better to escape all table and column names to prevent issues like that.
Escaping in MySQL is done with backtick symbol ` so your query will looks like:
UPDATE `table`
SET `read` = 1
WHERE `col1_id` = 2
AND `col3_id` = 1;
UPDATE tablename
SET `field_name` = 1
WHERE col1_id = 2
AND col3_id = 1;
UPDATE table
SET [read] = 1
WHERE col1_id = 2
AND col3_id = 1;
Hi all i have been writing a query and it is driving me crazy because it is giving me syntax error for ''
my query is
UPDATE test1 SET result =
CASE WHEN formula = "p1+p2" THEN 2
the error is here on line 2
any help is highly appreciated.
A case should always have an end:
UPDATE test1
SET result = (CASE WHEN formula = 'p1+p2' THEN 2 END);
This sets result to either "2" or NULL. You probably want:
UPDATE test1
SET result = 2
WHERE formula = 'p1+p2';
As a general rule, use single quotes for string constants. This is the ANSI standard.
String sql = ("insert into registration(pic) values(?) where email='"+Email+"' ");
i get error :error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where email='yyy#ymail.com'' at line 1
You have to use UPDATE query to pass it like
String sql = "UPDATE registration SET pic = ? WHERE email = '" + Email + "'";
Syntax for UPDATE query is
UPDATE table_name SET column_name = value;
Insert query format should be,
"insert into tablename (columnname) values(coulmnvalue)"
OR
"update registration set pic='' where email='"+Email+"'";
Yes. that is impossible.
Either you want:
insert into registration(pic) values(?)
Which will give you a new row;
Or you want an UPDATE:
UPDATE registration SET pic = ?
WHERE email = <EMAILYouWant>
Which will update an existing row where email = the record with the email you want to update the pic column.
below is my php snippet please how do i make my search to return result when i search for john doe am using a single search box in my php form with fname and lname saved in different column in my database. i only recive result when only fname or lname is searched.
$search_string = " AND (fname LIKE '%".mysql_real_escape_string($_REQUEST["string"])."%' OR lname LIKE '%".mysql_real_escape_string($_REQUEST["string"])."%')";
Please use MySQLi or PDO. mysql_* is deprecated and insecure.
I no longer use mysql_* so this syntax may be incorrect, but this should work:
$search = "Joe Bloggs";
$query = "SELECT * FROM users WHERE fname LIKE %$search% OR lname LIKE %$search%";