Microsoft SQL error in string for wrong syntax - sql

First time posting on here.
Please can someone help me with this very simple error that I cannot seem to fix.
if #DivResult > 0 and #IfMenu = ('A','F')
There is a syntax error near the comma

This is not valid tsql syntax: and #IfMenu = ('A','F')
The correct would be: and #IfMenu in ('A','F')

Related

UnhandledPromiseRejectionWarning: RequestError: Incorrect syntax near '17'

Using mssql(6.3.1) and node(14.15.1).
Query works when I use the template literal as shown in the documentation.
This was my query within template literal and it works. (DB names aren't variables here)
await sql.query`
INSERT
INTO
DB.DB.notes (updated_date,
updated_user,
note_description,
work_order_id,
created_date ,
created_user)
values(
${normalizedDate},
${username} ,
${note_description},
${wo_id},
${normalizedDate} ,
${username} )
`;
But when I try to replace the DB with variables let's say ${DB}, it is throwing error.
First it was saying
RequestError: Incorrect syntax near "."
and after that I got
RequestError: Incorrect syntax near "17" (it started from 14 and it's incremented to 17)
This is the documentation, and I have tried a ConnectionPool class, .query('/**query**/'), but none worked for me.
Please suggest what is wrong here.
The syntax you're using in your query generates a parameterised query.
It is not possible to paramaterise "identifiers" in queries. See Can I parameterize the table name in a prepared statement?

Ms Access Syntax issues

My problem is that I would like to realize this, but it throws syntax error.
WorkDayUltimate: Format(DateAdd("mm/dd/yy","h",-6,[Outgoing Date])
Thanks for your help in advance.
You must first add to date, then format:
WorkDayUltimate: Format(DateAdd("h",-6,[Outgoing Date]),"mm/dd/yy")

syntax error using convert function

I'm trying to convert a timestamp into yyyymm format, and have found that this should do the trick:
select convert(nvarchar(6),getnow(),112);
I try to run this just as a POC that it will return in the proper format, but I get the following error:
ERROR: 42601: syntax error at or near ","
It works fine when I take out the style argument, but obviously does not return the desired format. I have no idea what could be happening and any help would be greatly appreciated.
Thanks!
I don't know if Redshift allow to format like SQL Server does.
So I suggest you to try with datepart. Something like this:
SELECT CONVERT(NVARCHAR(6), DATE_PART(y, getnow()) || DATE_PART(mon, getnow()) )
In SQL Server, it's getdate()...
select convert(nvarchar(6),getdate(),112)
This is the equivalent in Redshift:
select to_char(sysdate,'YYYYMM')

SQL Syntax Error near ADD [duplicate]

This question already has an answer here:
Syntax error due to using a reserved word as a table or column name in MySQL
(1 answer)
Closed 8 years ago.
I've been staring at this thing for a while now and I can't seem to figure out what the syntax error is. I've been in this situation before and last time it was something so unbelievably simple I felt stupid afterwards. But here's to another attempt:
//update database
$q = "
UPDATE
users
SET
id='$edit_id',
name='$edit_name',
bdm='$edit_bdm',
add='$edit_add',
pc='$edit_pc',
location='$edit_outletL',
style='$edit_outletS',
coName='$edit_coName',
coNum='$edit_coTel',
coEmail='$edit_coEmail',
password='$edit_pass'
WHERE
id='$query_title'
";
$edit_query = mysql_query($q) or die("Database Query Error: ". mysql_error());
Database Query Error:
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 'add='Llancadle, Nr Barry', pc='CF62 3AQ', location='rural', style='food', coName' at line 1
You neeed to backquote add since it is a keyword:
`add` = ...
I think add is a reserved word in MySQL.
your problem is that "add" is a MySQL reserved word. See: http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html. If you have a column named "add", escape it like this:
//update database
$edit_query = mysql_query("UPDATE users SET id='$edit_id', name='$edit_name', bdm='$edit_bdm', `add`='$edit_add', pc='$edit_pc', location='$edit_outletL', style='$edit_outletS', coName='$edit_coName', coNum='$edit_coTel', coEmail='$edit_coEmail', password='$edit_pass' WHERE id='$query_title'") or die("Database Query Error: ". mysql_error());
as bobby noted in a comment, add is a mysql reserved word
`add`='$edit_add'
will tell mysql you are talking about a column

Can't figure out sql syntax error

I am trying to enter registration info into a mysql db through php, but the sql statement seems wrong. Can anyone please tell me what am I doing wrong?
INSERT INTO user(id,username,password,email,security_question,security_answer,face_photo,body_photo,user_salutation,user_firstname,user_middlename,user_lastname,parent_salutation,parent_firstname,parent_middlename,parent_lastname,gender,date_of_birth,address1,address2,country,state,city,pincode,country_code1,area_code1,phone1,country_code2,area_code2,phone2,alt_email,website,travel_within,passport,travel_companion,formal_education,other_qualification,known_languages,hobbies,about_you) VALUES('',some username,abcabc,abc#test.com,What is your first pet\'s name?,I don\'t know,'','',Mr.,sam,,fisher,Mr.,,,,Male,05/12/2009,test address1,,10,1073,16713,000000,00,00,00000000,,,,bcd#test.com,bcd#test.com,Within Country,on,on,none,none,spanish,none,none )
You don't have quotes around any of your string values:
..... ) VALUES('', 'some username', 'abcabc', 'abc#test.com'..... etc...