Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Arranging SQL Extract
#1
Hello Everyone,

I'm trying to extract the data content from SQL DB to Python and process and send an email (everything to be automated). However, i'm unable to do it as I am new to this and finding it difficult.

I have a DB columns with following fields and need to extract the data like below:
User Ticket TimeSpent
Raju T97234 30
Ram T23422 60
John T23423 45
Raju T97231 50
Raju T97234 25
Sam T07074 45
Raju T63482 60
Ram T72934 20
John T19384 15
Sam T97744 90

I am unable to get the data like this, it just comes with the extract without header, I am using pyodbc to do it.
Q1: What is the best library to work with SQL?
Q2: How can I organize data and groupby the User Column?
Q3: The output I get is only data in the list, not the column header ('User','Ticket','TimeSpent')

import pyodbc
conn = pyodbc.connect('DRIVER={SQL Server};SERVER=MSSQLSRV0001\MSSQLINS100;DATABASE=TicketTracker;UID=SUser;PWD=password') 

cursor = conn.cursor()
cursor.execute('SELECT * FROM TicketTracker.dbo.TicketRecords')
myrow = cursor.execute('SELECT * FROM TicketTracker.dbo.TicketRecords')
result = myrow.fetchall()
result
Output:
('Raju','T97234','30') ('Ram','T23422','60') ('John','T23423','45')
Reply


Messages In This Thread
Arranging SQL Extract - by Ranjirock - Dec-31-2019, 07:46 AM
RE: Arranging SQL Extract - by ndc85430 - Dec-31-2019, 08:47 AM
RE: Arranging SQL Extract - by Ranjirock - Dec-31-2019, 10:50 AM
RE: Arranging SQL Extract - by Ranjirock - Jan-02-2020, 02:53 PM
RE: Arranging SQL Extract - by sandeep_ganga - Jan-02-2020, 03:44 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020