Sep-13-2018, 07:42 PM
(Sep-13-2018, 03:25 PM)kat35601 Wrote: This is my first query using python.
how would I drop the "u" and "decimal" from the printed results?
also is correct way to print the results? It does seem to put me in an endless loop.
for row in cursor.execute('select top 1 ompSalesOrderID, ompfullorderSubtotalBase from server.dbo.SalesOrders left join server.dbo.SalesOrderLines on omlSalesOrderID=ompSalesOrderID '): while row: print ((row[0] , row[1]) )Thanks for the Guidance
Try
for row in cursor.execute('...'): for cell in row: print(cell, sep=',')If you know indices of the "interesting" fields - and they are few, e.g. elements 2, 6 and 1 - you can print like this
print('{2}, {6}, {1}'.format(*row))(see this page for explanation)
Since
row
in your example does not change - remains non-empty tuple, which in Python is one of True
equivalents - endless loop is the expected behaviour.
Test everything in a Python shell (iPython, Azure Notebook, etc.)
- Someone gave you an advice you liked? Test it - maybe the advice was actually bad.
- Someone gave you an advice you think is bad? Test it before arguing - maybe it was good.
- You posted a claim that something you did not test works? Be prepared to eat your hat.