I have Syntax error: Unexpected keyword SET - sql

Here is my code but I keep getting the error message Syntax error:
Unexpected keyword SET at [4:1]
SELECT start_station_id
FROM `cyclist-bike-share-success.Trip_data_2022_.April_2022`,
UPDATE `cyclist-bike-share-success.Trip_data_2022_.April_2022`,
SET start_station_id='unknown',
WHERE start_station_id IS NULL
Any advice?

Try to read the documentation about how to write queries.
For your question, try to write like below:
SELECT start_station_id
FROM `cyclist-bike-share-success.Trip_data_2022_.April_2022`;
UPDATE `cyclist-bike-share-success.Trip_data_2022_.April_2022`
SET start_station_id='unknown'
WHERE start_station_id IS NULL

Related

MariaDB: subselect in COALESCE throws ERROR 1064 (42000)

Intention: I want to subselect values within a coalesce function in MariaDB (10.7.1).
Problem:
Executing this SQL statement ...
select coalesce(select id from MY_TABLE limit 1);
... throws this error message:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'select id from MY_TABLE limit 1)' at line 1
Workarounds / checks I tried:
select id from MY_TABLE limit 1; returns a valid value. So that part of the statement is fine.
select coalesce('a'); returns the value a. So executing coalesce with one parameter only is also fine.
You must make the result of select to be an expression. Statement is not an expression
with MY_TABLE as (
select 1 as id
)
select coalesce((select id from MY_TABLE limit 1)) c;
Note the result of LIMIT without ORDER BY is an arbitrary row.
The COALESCE function typically takes 2 or more arguments. The value returned is the first value which is not NULL. You probably intend something like this:
SELECT COALESCE(id, 'missing') AS id
FROM MY_TABLE
ORDER BY <some column>
LIMIT 1;

How to fix Incorrect syntax near the keyword 'where'

this SQl statement is throwing error Incorrect syntax near the keyword 'where'. I am not exactly sure what is the issue. It is just a update statement and I am trying to get the user_id from another table where user_name is this.
statement:
update esg.client_user_pref where client_user_id = (select U.CLIENT_USER_ID from esg.CLIENT_USER U where U.USER_NAME='CorpESignClientUser') and pref_entity = 'UsageMode' and pref_attrb = 'ExpirationAfterDay' set pref_value = '15';
Thanks
wrong sequence:
right: update ... set ... where ...
wrong: update ... where .... set
The correct syntax for UPDATE query is
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
AS per your code above this should do the trick
update table esg.client_user_pref
set pref_value = '15'
where client_user_id =
(select U.CLIENT_USER_ID from esg.CLIENT_USER U where U.USER_NAME='CorpESignClientUser')
and pref_entity = 'UsageMode' and pref_attrb = 'ExpirationAfterDay' ;

Sql update statement says an error

Iam updating an temporary table from the original table
but it is having some issues can anyone help me for this problem
here is my code and the error
The below given statement says Incorrect syntax near the keyword 'group'.
Update #tmpODU set Tn1Cnt=1,TnPay=isnull(sum(Amt),0)
From Table1
where Code COLLATE DATABASE_DEFAULT=TcCode
COLLATE DATABASE_DEFAULT and Del='R' and Date<=dateadd(M,#n1D,#dDate)
group by Code
can anyone help me...
thank you.....
i got the answer using below statment
and it is working as i expected
Update #tmpODU
set Tn1Cnt=1,
Tn1Pay=isnull((select sum(Amt)
From table1
where Code COLLATE DATABASE_DEFAULT=TcCode COLLATE DATABASE_DEFAULT
and Del='R'
and Date<=dateadd(M,#n1D,#dDate) group by Code),0)

Using Case statement within update clause - Sybase

The following is sybase code. Can someone see if the following is correct. I guess I'm missing out on the syntax somewhere
declare #test varchar(32)
select #test="/data/dump/team/"
update link
set link.value=
case when #test=substring(link.value,1,17)
then #test
when #test != substring(link.value,1,17)
value
end
where link.value != ""
and link_id=0 and row_id = 462135
As it is give me the following error: "Incorrect syntax near keyword end on line 10."
Can please someone help me with the syntax.
Try adding "then" to the second case:
declare #test varchar(32)
select #test="/data/dump/team/"
update link
set link.value=
case when #test=substring(link.value,1,17)
then #test
when #test != substring(link.value,1,17)
then value
end
Why not simply do an "else" for the second "when" ?

SQL: Why can't I set a variable to the result of a query?

I'm trying to run this query on the SO Data Explorer:
DECLARE #totalRep float
SET #totalRep = SELECT SUM(Users.Reputation) FROM Users
And I keep getting
Incorrect syntax near the keyword 'SELECT'.
What am I doing wrong?
SELECT #totalRep = SUM(Users.Reputation) FROM Users