Micro Focus QTP (UFT) Forums
using queries in functions (Store Procedures) - 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: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: using queries in functions (Store Procedures) (/Thread-using-queries-in-functions-Store-Procedures)



using queries in functions (Store Procedures) - samson - 03-12-2010

Hi all,

Code:
if not exists (select l.Locality from TgnTerritorydtl tdtl, tgnLocality l, Tgncompany C
where
l.localityid= tdtl.localityid and c.companyid=l.companyid and
c.company='company' and l.Locality='123')
print 'WARNING: Locality not Exists'
else
Print 'Locality Exists'

now my issue is : How do i use this type of query or store procedure in QTP 10,
Note: while creating DBcheckPoint it could not create. and while pasting this in function too QTP 10 shows errors, so how do i do , if kindly help,
Waiting for the reply thank you.
Note 1: while replacing print with MsgBox too errors were found.
Thank you,
Samson.B


RE: using queries in functions (Store Procedures) - Saket - 03-12-2010

Hi Samson,
you can not directly use a query to put in if condition.
you will need to exceute these query and compare the recordset.

steps you can follow -
1 connect to DB
2 execute your query
3 get the recordset
4 then compare the values

e.g in your case here

Code:
Dim oConnection,ConnectionString  , oRecordSet

ConnectionString ="<Connection string to Connect to DB>"  'refer https://www.learnqtp.com/qtp-database-part2-how-to-create-connection-strings/

Set oConnection = CreateObject("ADODB.Connection")  
Set oRecordSet = CreateObject("ADODB.Recordset")
oConnection.Open ConnectionString  
strSQL = "select l.Locality from TgnTerritorydtl tdtl, tgnLocality l, Tgncompany C where
l.localityid= tdtl.localityid and c.companyid=l.companyid and
c.company='company' and l.Locality='123'"
oRecordSet.Open strSQL,oConnection, adOpenStatic    

if oRecordSet.Fields("Locality").value <> null then 'or you can get the record count here if > 0 then locality exists
print "Locality Exists"
else
print "Locality Not Exists"
end if

while creating DBCheckpoint put the same query there.