how do i extract data from sql in python? I have this code but it is repeating all the values which is not what i want. I wish to have new updated sql data to be in my python. I am almost struck for a few days..Any kind soul pls I am using sqlserver2012, python
import time
sql_conn = connectSQLServer('ODBC Driver 13 for SQL Server', 'DESKTOP-K6A10IO\SQLEXPRESS', 'display')
mycursor = sql_conn.cursor()
a = 0
while True:
try:
time.sleep(1)
a=a+1
print(a)
sql = "SELECT * FROM dbo.LiveStatsFromSQLServer"
mycursor.execute(sql)
myresult = mycursor.fetchall()
for x in myresult:
print(x)
except Exception as error:
print("Nothing in database\n")
print(error)
sql_conn.commit()
The result shown is
1
(1625, 3)
(1626, 0)
(1627, 10)
2
(1625, 3)
(1626, 0)
(1627, 10)
3
(1625, 3)
(1626, 0)
(1627, 10)
(1622, 20)
while i wish to have a constantly updating to the end of the list like:
(1625, 3)
(1626, 0)
(1627, 10)
after 1 second
(1622, 20)
after 1 second
(1612, 10)