Home > Mobile >  How to pass python loop i to sql select top i number of rows
How to pass python loop i to sql select top i number of rows

Time:06-17

I am new to python and sql bear with my knowledge.

I want to run a query where I can get top (looped variable) while running sql in python compiler.

Eg

For I in range(1,5) :
    Query = " Select top" I" * from sales"

So that can get the top 1st row in first I loop and top 2nd row in next I loop and goes on. Please assist.

CodePudding user response:

You use string replacement as prepared statements will not work

for I in range(1,5) : 
    Query = " Select top {} * from sales".forma(I)
  • Related