0

example :

product = ["Neil O'Biran",'ahs9029','One thing that is "contant" is',None]

now inorder to insert into sql server, we need everythin in single quotes, so i used.

','.join('"{0}"'.format(w) for w in product)

this will give output

'Neil O'Brian','ahs9029','One thing that is "contant" is','None'

My question is how do we get rid of the single quote in the name and the double quotes in "Constant" ?

So that everything is encompassed in single quotes and can be inserted into sql server using stored procedures in my case.

Only values containing single quotes can be inserted into sql server, with insert command, how do you handle values which are as dynamic as i h ave showed in the example, in one case a name contains a single quote, in the other there are double quotes in the strings. How do you replace them all before inserting ?

  • 1
    Possible duplicate of [How to put parameterized sql query into variable and then execute in Python?](https://stackoverflow.com/questions/1633332/how-to-put-parameterized-sql-query-into-variable-and-then-execute-in-python) – Cid Nov 27 '18 at 10:36
  • +1 on using parameters. Alternatively you can pass a whole JSON doc to SQL Server and parse it in the query, using the OPENJSON function: https://learn.microsoft.com/en-us/sql/t-sql/functions/openjson-transact-sql?view=sql-server-2017 – David Browne - Microsoft Nov 27 '18 at 13:13

0 Answers0