Hi VarunKarthi,
We can use OTA code for run the SQL Queries and export their output to excel sheet.
Please find below example:
Module Module2 Sub Main() Dim td td = CreateObject(“TDApiOle80.TDConnection”) td.InitConnectionEx(“http://qc10/qcbin") td.ConnectProjectEx(“DEFAULT”, “PM_AND_SRT”, “svanumu”, “ABCD”) Dim com As TDAPIOLELib.Command Dim RecSet As TDAPIOLELib.Recordset ‘ Setting and executing the SQL com = td.Command com.CommandText = “SELECT DISTINCT bug.bg_project AS System FROM BUG WHERE (bug.bg_user_template_01 ‘Deferred’ AND bug.bg_user_template_01 ‘Closed’ AND bug.bg_user_template_01 ‘Closed – Approved’) AND ((datediff (dd, bug.bg_detection_date , getdate ())) > 7)” RecSet = com.Execute Console.WriteLine(“Initial Count” + RecSet.RecordCount.ToString) Console.ReadLine() ‘ Displaying the 2nd column data Dim rand As New Random Dim index As Integer Dim System_Name As String = Nothing index = rand.Next(1, RecSet.RecordCount) For i = 1 To RecSet.RecordCount If i = index Then ‘Console.WriteLine(“System Name:” + RecSet.FieldValue(0)) System_Name = RecSet.FieldValue(0) Console.WriteLine(“System Name:” + System_Name) Exit For End If RecSet.Next() Next Dim com1 As TDAPIOLELib.Command Dim RecSet1 As TDAPIOLELib.Recordset Dim Excel, Sheet Excel = CreateObject(“Excel.Application”) ‘ Open Excel Excel.WorkBooks.Add() ‘ Add a new workbook ‘ Get the first worksheet. Sheet = Excel.ActiveSheet Dim Row Row = 1 ‘ Setting and executing the SQL com1 = td.Command com1.CommandText = “SELECT bug.bg_project AS System, bug.bg_bug_id AS Defect_ID,bug.bg_summary AS Summary, bug.bg_severity AS Severity,bug.bg_user_template_01 AS Status,bug.bg_user_template_09 AS Team,bug.bg_responsible AS Assigned_To,BUG.BG_DETECTION_DATE AS Detection_Date FROM BUG WHERE bug.bg_project= ‘” + System_Name + “‘ and (bug.bg_user_template_01 ‘Deferred’ AND bug.bg_user_template_01 ‘Closed’ AND bug.bg_user_template_01 ‘Closed – Approved’) AND ((datediff (dd, bug.bg_detection_date , getdate ())) > 7)” RecSet1 = com1.Execute Console.WriteLine(“Final Count” + RecSet1.RecordCount.ToString) Console.ReadLine() For i = 1 To RecSet1.RecordCount ‘Console.WriteLine(RecSet1.FieldValue(0) + “|” + RecSet1.FieldValue(1) + “|” + RecSet1.FieldValue(2) + “|” + RecSet1.FieldValue(5) + “|” + RecSet1.FieldValue(6)) Sheet.Cells(Row, 1).Value = RecSet1.FieldValue(0) Sheet.Cells(Row, 2).Value = RecSet1.FieldValue(1) Sheet.Cells(Row, 3).Value = RecSet1.FieldValue(2) Sheet.Cells(Row, 4).Value = RecSet1.FieldValue(3) Sheet.Cells(Row, 5).Value = RecSet1.FieldValue(4) Sheet.Cells(Row, 6).Value = RecSet1.FieldValue(5) Sheet.Cells(Row, 7).Value = RecSet1.FieldValue(6) Row = Row + 1 RecSet1.Next() Next Excel.ActiveWorkbook.SaveAs(“c:\temp\Aged_Defects_ProjectWise.xls”) Excel.Quit() ‘Console.WriteLine(RecSet.FieldValue(0) + “|” + RecSet.FieldValue(1) + “|” + RecSet.FieldValue(2) + “|” + RecSet.FieldValue(5) + “|” + RecSet.FieldValue(6)) Console.ReadLine() td = Nothing End Sub End Module
Regards,
Srihari