Nov-18-2022, 07:40 PM
Hi Team,
I am extracting sql table data via python , while extracting data , portfolio contains single quote in its records.
hence my second select query is not working. due to single quote in strings portfolio.
how to handle dynamically.
and portfolio = ‘xx_xxxxx_spread_jun’22’ <-------------‘22’ issue here.
select * from customer.table1 where
MarketDate = '2022-06-30-00:00:00'
and portfolio = 'xx_xxxxx_spread_jun'22'
clubbing sql records and header into variable Info.
I am extracting sql table data via python , while extracting data , portfolio contains single quote in its records.
hence my second select query is not working. due to single quote in strings portfolio.
how to handle dynamically.
and portfolio = ‘xx_xxxxx_spread_jun’22’ <-------------‘22’ issue here.
select * from customer.table1 where
MarketDate = '2022-06-30-00:00:00'
and portfolio = 'xx_xxxxx_spread_jun'22'
clubbing sql records and header into variable Info.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
1 ) first query. result = cursor.execute(qr1) for idx,row in enumarate(result,start = 1 ) info = dict ( zip (hd,row)) qry2 = """select * from {database}.[dbo].[{tbl}] where [MarketDate] = '{info[MarketDate]}'and [Portfolio] = '{info[Portfolio]}""" 2 ) second query. output2 = cursor.execute(qr2) < - - - - - - - unable to execute query2 |