Skip to content

Instantly share code, notes, and snippets.

@clintmjohnson
Last active November 26, 2015 16:37
Show Gist options
  • Save clintmjohnson/74528e2643318c6f004b to your computer and use it in GitHub Desktop.
Save clintmjohnson/74528e2643318c6f004b to your computer and use it in GitHub Desktop.
This Gist Uses Python and SQL Server - It queries results from a MSSQL table and appends the results to a python list
import _mssql
# Connect to the SQL Server Database
conn = _mssql.connect(server='Servernamehere', user='serverusername', password='serverpassword', \
database='databasename')
# Run The Select Query against the Database
conn.execute_query('SELECT TOP 10 [Item ID],[Custom Label],[Quantity Available] FROM [bsusa_active_staging]')
# Create the Lists
ItemID = []
CustomLabel = []
Quantity = []
# Insert the SELECT query results into the Lists
for row in conn:
ItemID.append("%s" %(row['Item ID']))
CustomLabel.append("%s" %(row['Custom Label']))
Quantity.append("%s" %(row['Quantity Available']))
#print("%d,%s,%s"%(row['Item ID'],row['Custom Label'],row['Quantity Available']))
print(ItemID)
print(CustomLabel)
print(Quantity)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment