Extract tables with specific parameters from MSQL ( Csv file ) ...

Discussion in 'Python' started by Penny1mx, Jan 21, 2022.

Tags:
  1. Penny1mx

    Penny1mx New Member

    Joined:
    Jan 20, 2022
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    Hi guys !!!

    I'm new on python programming, I think I learn fast ( I hope hehehehe ), I create this little script to connect to a database extract some tables with specific parameters, and put them in a CSV file:

    import pandas as pd
    import pyodbc
    import csv
    conn = pyodbc.connect('Driver={SQL Server};'
    'Localhost;'
    'Username = test;'
    'password = test;'
    'Database=TEST;'
    'Trusted_Connection=yes;')
    sql_query = pd.read_sql_query('''
    select * from TEST.dbo.TABLE01
    '''
    ,conn)
    df = pd.DataFrame(sql_query)
    df.to_csv (r'D:\\TABLE01.csv', index = False, sep = ',', quotechar = '"', quoting=csv.QUOTE_ALL)​

    But, I won't add the option to offer me native export from SQL:

    upload_2022-1-21_9-27-0.png

    In specific:
    • Locale ( Spanish (Mexico) )
    • Code page: 1252 (ANSI - Latin I)
    Can you help me to add these lines to my code ???

    Thanks so much, guys !!!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice