How to execute a Parametrized SQL query in QTP script?

Questions by mangipudi

Showing Answers 1 - 5 of 5 Answers

narendra simha.talluri

  • Mar 13th, 2006
 

To execute a parameterized SQL query follow the below procedure:


Step 1: Connect to Database using existing DSN (Data Source Name)


Step 2: Execute selected parameterized SQL query on that database.

Procedure:

a) Choose insert>checkpoint>database check point. Then the Data base query
wizard opens


b) Select your database selection preferences and click Next .



Now you can choose below options :

@ create query using Microsoft Query-opens Microsoft query, enabling you to
create a new parameterized SQL query. Once you finish defining your query, you
return to Quick Test. This option is available only if you have Microsoft
query installed on your computer.

@ specify SQL statement manually-opens the specify SQL statement screen in the
wizard, which enables you to specify the connection string and an SQL
statement.

@ show me how to use Microsoft query-Displays an instruction screen when you
click Next before opening Microsoft query.



c) if you choose create query using Microsoft Query ,Microsoft Query opens.
Choose a data source and define a query. If you choose Specify SQL statement
manually the specify SQL statement

screen opens. Now specify the connection string and the SQL statement, and click
Finish.


d) The checkpoints Properties dialog box opens. Select the checks to perform
on the result set. you can also modify the expected data in the result set.


e) click OK to close the dialog box.


Step 3: Retrieve select statement result into excel sheet (.excel)

Step 4: Analyze that result .


To follow the above approach Testing Team receive below information from
Development Team

1. DSN (Data Source Name)

2. Table Definitions

3. Forms vs Tables

these three are combine called as Data Design Document (DDD).


Thanks.

Narendra Simha Talluri

  Was this answer useful?  Yes

kaushikrroy

  • Mar 19th, 2006
 

Hi Narendra,


Thanks for the information.


Actually my requirement is, query should be parametrized. i.e, query should
be in the script and also it should change dynamically. i.e I have to pass
different values in the query condition field based on different criteria's.
(Where condition)

In this procedure (Which you have mention) can we change the SQL query? If we
can please let me know once.

For this I am following the below process (Which I came to know recently). Here
I am giving the procedure. Please check it once.


1 Connect to the database:



strCon="Driver={Microsoft ODBC for Oracle}; " &_

"CONNECTSTRING = (DESCRIPTION = " &_

"(ADDRESS = (PROTOCOL = TCP)" &_

"(HOST=XXXX) (PORT=XXXX))" &_

"(CONNECT_DATA = (SERVICE_NAME=xxxxxxx))); uid=xxxxx;pwd=xxx;"



2. Open the database connection



Set oCon=CreateObject("ADODB.Connection")



3. Create the recordset object



Set oRs=CreateObject("ADODB.Recordset")



4. Define the Parameterized SQL query



strQuery="Parameterized query"



5. Execute the query



Set oRs=oCon.Execute(strQuery)



After that we can manipulate the record set values accordingly.


Thanks,

Prabhakar.

  Was this answer useful?  Yes



Set dbexample = CreateObject("ADODB.Connection")
dbexample.Open "dsn=;" & _
"uid=;" & _
"pwd=;"

strRequiredNameCode = DataTable.Value("strRequiredNameCode")
sql = "Select Name from ORGANIZATION where CODE='" & strRequiredNameCode & "'"
'TODO - execute your sql, etc.
set Query = dbexample.execute(sql)
 Output = Query.GetString
msgbox Output

I hope my code will help you to solve your problem!!!!!


Richi

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions