VB, Teradata

Hello,

Need to query a Teradata Table and if the record exist return code 0 if not sleep for 5 min and try again until record found. Preferably in VB.Net or VBS. Thanks
DoukAliAsked:
Who is Participating?
 
Robberbaron (robr)Connect With a Mentor Commented:
i assume you have a ODBC driver installed for Teradata. ?

see http://www.connectionstrings.com/teradata

try this code..... written from scratch and not tested for syntax.




Dim objConnection
Set objConnection = CreateObject("ADODB.Connection")
objConnection.ConnectionString =
      "Provider=Teradata;DBCName=MyDbcName;Database=myDataBase; Uid=myUsername;Pwd=myPassword;"
objConnection.ConnectionTimeout = 0
objConnection.Open

Set rs = CreateObject("ADODB.recordset")
strSQL = "SELECT * FROM myTable"

maxcount = 10  'dont allow an infinite loop
count=0 : ok = false
do while count<maxcount and ok=false
     rs.open strSQL, objConnection , 3,3
     if rs.eof then
         'no records so wait
         count=count+1
         rs.close
         xx = timer
         do while timer < xx + 6000 * 5  'waite 5minutes
             do events
         loop
       else
          'records returned
          ok =true
     end if
loop
    
if ok then 
   'work on records
 else
   wscript.echo "gave up waiting after " & maxcount & " tries"
end if

rs.Close
Set rs = Nothing

objConnection.Close
Set objConnection= Nothing

Open in new window

0
 
Brook BraswellApplication Development ManagerCommented:
The query should be structured the same for any size database
if your dataset returns 0 records then sleep.
but because you are looking at such a large table I would have to ask...

What does the query look like?  - perhaps your problem is in getting a fast response.


sql = "SELECT DATA FROM YOURTABLE WHERE CONDITION = TRUE"
DIM DR AS DATAROW
DIM SQLCMD AS NEW OLEDB.OLEDBCOMMAND(SQL,OPENSQLCONN)
DIM SQLDS AS NEW DATASET
DIM SQLDA AS NEW OLEDB.OLEDBDATAADAPTER(SQLCMD)
SQLDA.FILL(SQLDS)
IF SQLDS.TABLES(0).ROWS.COUNT = 0 THEN
'   SLEEP PROCESS
ELSE
  ' DO YOUR KEWL THING HERE
END IF
0
 
DoukAliAuthor Commented:
The table I'm querying is very small (about 10 records). I'm running some processes and whenever one finishes it would write to a table by updating the value of a column to 1. What I need to do is have this vb code check the table for that value and either return a code ... or just write 'done' in a txt file.

Thanks for your help.
0
 
LowfatspreadCommented:
main thing to  remember then is to make sure that the sql code runs in its own transactionn
so that you don't cause contention locks...

begin tran
select x...
commit tran
test
   sleep
else
   do something
0
All Courses

From novice to tech pro — start learning today.