Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBScript question regarding loop control structure

Status
Not open for further replies.

fchan

MIS
Jul 2, 2001
47
0
0
US
I am creating an SQL statement from an array. The values in the array supply the values for the WHERE clause of my SQL statement. Here's my code:

**************
Dim strPostingSQL, strWhere, iLoop
strPostingSQL = "DELETE FROM tblCurrentJobs WHERE "

For iLoop = LBound(arrPostings) to UBound(arrPostings)
strWhere = strWhere & "PostingID = " & _
Trim(arrPostings(iLoop)) & " or "
Next

strPostingSQL = strPostingSQL & strWhere
***************

My SQL statement is created fine, but it always has an extra "or" at the end of the statement. How do I get rid of the extra "or"?

Thanks
 
Try:


Dim strPostingSQL, strWhere, iLoop
Dim blnFirst As Boolean

strPostingSQL = "DELETE FROM tblCurrentJobs WHERE "
blnFirst = True
For iLoop = LBound(arrpostings) To UBound(arrpostings)
If Not blnFirst Then strWhere = strWhere & " or "
If blnFirst Then blnFirst = False
strWhere = strWhere & "PostingID = " & _
Trim(arrpostings(iLoop))
Next

strPostingSQL = strPostingSQL & strWhere


Mark
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top