Skip to content

Instantly share code, notes, and snippets.

@tinybike
Created September 14, 2014 23:32
Show Gist options
  • Save tinybike/7700762729daed8c786a to your computer and use it in GitHub Desktop.
Save tinybike/7700762729daed8c786a to your computer and use it in GitHub Desktop.
connect julia to mssql using the magic of pycall
# connect julia to mssql using the magic of pycall
# @author Jack Peterson (jack@tinybike.net)
using PyCall
@pyimport pymssql
# Connect to MSSQL Server
conn = pymssql.connect(server="SERVER:PORT",
user="USER",
password="PASSWORD",
database="DATABASE")
# Create a database cursor
cursor = conn[:cursor]()
# Replace this nonsense with your own query :)
query = "SELECT TOP 25 *
FROM FSDBDATA.dbo.MS04311
WHERE sitecode LIKE 'PRIMET'
ORDER BY DATE_TIME DESC"
# Execute the query
cursor[:execute](query)
# Go through the results row-by-row and print them out.
for row in cursor
println(row)
end
cursor[:close]()
conn[:close]()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment