title: How do I create a csv file using Python from sybase db table depending on a value in a column of that table?
body: <p>I am new at python and trying to write a script which connects with the database(Sybase ase) and copies the data present the table in the specific size of CSV files depending on one column in the table(index)</p>
  
  <p>Code that I have tried:</p>
  
  <pre><code>server = 'XYZ' 
  database = 'user_details' 
  username = '' 
  password = '' 
  #have used sql express for now
  import pyodbc
  import csv
  db = pyodbc.connect('DRIVER={SQL Server};SERVER='+server+';DATABASE='+database+';UID='+username+';PWD='+password+'')
  c = db.cursor()
  c.execute("SELECT * FROM userinfo")
  list1 = c.fetchall()
  #print (list1)
  cursor = db.cursor()
  cursor.execute("SELECT * FROM userinfo;")
  with open("C:\\Users\\ABC\\Desktop\\out.csv", "w", newline='') as csv_file:
   csv_writer = csv.writer(csv_file)
   csv_writer.writerow([i[0] for i in cursor.description]) # write headers
   csv_writer.writerows(cursor)
  </code></pre>
  
  <p>Now, I want to make CSV in batches. Like for eg. first 100 records of the table in 1 file(file_1.csv) and next 100 records in another file(file_2.csv). Depending on the output of the select statement.</p>
  
  <p>How do I create a csv file using Python from sybase db table depending on a value in a column of that table?</p>