Solved

VB, Teradata

Posted on 2011-02-22
4
752 Views
Last Modified: 2013-12-25
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
0
Comment
Question by:DoukAli
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 500 total points
ID: 34960222
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
 
LVL 14

Expert Comment

by:Brook Braswell
ID: 34960284
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
 

Author Comment

by:DoukAli
ID: 34965321
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
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 34982240
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Collapse and expand table in Word 2010 2 163
Remove Exif Orientation before adding image to db 9 63
Assign a value in Excel V-Basic 3 38
Add a second combobox VBA Excel 8 48
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question