Micro Focus QTP (UFT) Forums
SQL quering - how to use results of one query in the following one - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: SQL quering - how to use results of one query in the following one (/Thread-SQL-quering-how-to-use-results-of-one-query-in-the-following-one)

Pages: 1 2


RE: SQL quering - how to use results of one query in the following one - Saket - 01-13-2010

Why can't I edit or delete my posts, by the way? - It has been reported to administrator, hopefully it will be resolved soon.
always post the resolutions also if you have resolved any of query, so that it may help others.


RE: SQL quering - how to use results of one query in the following one - unbeliever - 01-13-2010

Ok, I wanted to use results of one query in subsequent one and my solution is working and looks as shown below. Though it works I am looking forward to optimizing it and if anyone have any ideas I would gladly consider them, please contribute.

In this solution I extended sql queries to have only one option left for selection.

Code:
Dim Conn
Dim Rs
Dim strQuery
Set Conn = CreateObject("ADODB.Connection")
Set Rs = CreateObject("ADODB.Recordset")
strQuery = "Select wkf_order_id, completion_time from v_order where USERID_REQUESTOR = 'ILMT12' and SERVICE_NAME = 'Mailbox'"
Rs.CursorType = 1
Conn.Open "Driver={Microsoft ODBC for Oracle};Server=myserver.com;Uid=user;Pwd=pwd;"
Rs.Open strQuery, Conn
Recordcount = Rs.RecordCount
DataTable.GlobalSheet.AddParameter "WKF_ORDER_ID",""

While (NOT Rs.EOF)
For i=1 to Recordcount
DataTable.SetCurrentRow(i)
DataTable("WKF_ORDER_ID", DtGlobalSheet) = Rs.Fields("WKF_ORDER_ID")
Rs.MoveNext
Next
Wend
Conn.close
Set Conn = Nothing
Set Rs = Nothing


Dim Conn2
Dim Rs2
Dim strQuery2
Set Conn2 = CreateObject("ADODB.Connection")
Set Rs2 = CreateObject("ADODB.Recordset")
WKF_ORDER_ID = DataTable.GlobalSheet.GetParameter("WKF_ORDER_ID").ValueByRow(1)
strQuery2 = "select REQUEST_COMPONENT from taudit where USERID_USR = 'ILMT21' and AUDITSINGLEID = '" & WKF_ORDER_ID & "' and userid_actor = 'ILMT12'"
Rs2.CursorType = 1
Conn2.Open "Driver={Microsoft ODBC for Oracle};Server=myserver.com;Uid=user;Pwd=pwd;"
Rs2.Open strQuery2, Conn2

Recordcount2 = Rs2.RecordCount
DataTable.GlobalSheet.AddParameter "REQUEST_COMPONENT", ""

While (NOT Rs2.EOF)
For x=1 to Recordcount2
DataTable.SetCurrentRow(x)
DataTable("REQUEST_COMPONENT",DtGlobalSheet) = Rs2.Fields("REQUEST_COMPONENT")
Rs2.MoveNext
Next
Wend

Conn2.close
Set Conn2 = Nothing
Set Rs2 = Nothing

wait(3)

Req_Comp = DataTable.GlobalSheet.GetParameter("REQUEST_COMPONENT").ValueByRow(1)
If Req_Comp = "IPS" Then
    Reporter.ReportEvent micPass,"IPS entry is found" ,"Success"
        Else  Reporter.ReportEvent micFail,"IPS entry not found" ,"Fail"
End If



RE: SQL quering - how to use results of one query in the following one - Saket - 01-13-2010

@Everyone - Always wrap your code with proper tags to make your post more readable.
unbeliever -I have already done this for you for this post Smile