Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SQL Query in python file shows up as "COLUMNS" instead of "VALUES"

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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…

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading