SQL Query in python file shows up as "COLUMNS" instead of "VALUES"
Question:
I am very new at this, and im trying my best but i simply cant see where im f…ing up =(
I have made an SQL Query in my python file. I want to write to my Azure database table –> make a new row
the query is this:
SQLQuery ="""
INSERT INTO [dbo].[Input_Table_Test]
VALUES ("""+(respons['symbol'])+""",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);"""
The "respons [‘symbol’]" is a dynamic JSON element and im trying to get the key uploaded into the query
(in this case its ‘SMG’) – dont worry about all the 1s, its just because so it fits the table.
When im running the query from my python file im getting this error message:
(’42S22′, "[42S22] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Invalid column name ‘SMG’.")
but im not trying to write to the columns, im trying to make row/values.
I tried editing the query to see if something else was wrong but no. If you replace "(respons[‘symbol’])" with a 1 it works perfectly. i dont know where to go from here…
Answers:
1
is an integer, which does not need to be quoted.
But SMG
is (presumably) intended to be a string, and thus would need quotes around it like so 'SMG'
.
But because you didn’t quote it, it’s being interpreted as the name of some other column in the table. And of course you don’t have a column named that, so you get the error.
Put quotes around SMG
.
I am very new at this, and im trying my best but i simply cant see where im f…ing up =(
I have made an SQL Query in my python file. I want to write to my Azure database table –> make a new row
the query is this:
SQLQuery ="""
INSERT INTO [dbo].[Input_Table_Test]
VALUES ("""+(respons['symbol'])+""",1,1,1,1,1,1,1,1,1,1,1,1,1,1,1);"""
The "respons [‘symbol’]" is a dynamic JSON element and im trying to get the key uploaded into the query
(in this case its ‘SMG’) – dont worry about all the 1s, its just because so it fits the table.
When im running the query from my python file im getting this error message:
(’42S22′, "[42S22] [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]Invalid column name ‘SMG’.")
but im not trying to write to the columns, im trying to make row/values.
I tried editing the query to see if something else was wrong but no. If you replace "(respons[‘symbol’])" with a 1 it works perfectly. i dont know where to go from here…
1
is an integer, which does not need to be quoted.
But SMG
is (presumably) intended to be a string, and thus would need quotes around it like so 'SMG'
.
But because you didn’t quote it, it’s being interpreted as the name of some other column in the table. And of course you don’t have a column named that, so you get the error.
Put quotes around SMG
.