Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1 step: Create a temporary table with pyodbc into sql server for objects
- 2 step: Select objects from temporary table and load it into pandas dataframe
- 3 step: print dataframe
- import codecs
- import os
- import io
- import pandas as pd
- import pyodbc as po
- server = 'sql_server'
- database = 'sql_database'
- connection = po.connect('DRIVER={SQL Server};SERVER='+server+';DATABASE='+database+';Trusted_Connection=yes;')
- cursor = connection.cursor()
- query1 = """
- CREATE TABLE #ttobject (object_nr varchar(6), change_date datetime)
- INSERT INTO #ttobject (object_nr)
- VALUES
- ('363964'),
- ('349897'),
- ('371966');
- """
- query2 = """
- SELECT *
- FROM #ttobject
- Drop table if exists #ttobject
- """
- cursor.execute(query1)
- df = pd.read_sql_query(query2, connection)
- print(df)
- ('HY000', '[HY000] [Microsoft][ODBC SQL Server Driver]Connection is busy with results for another hstmt (0) (SQLExecDirectW)')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement