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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urgent help needed with SQL string concatenation 1

Status
Not open for further replies.

SmileyFace

Programmer
Sep 10, 2002
99
US
I have a problem trying to get this SQL statement to work. Obviously, if you see the flow, it attaches an 'OR' to the last line of the where clause and hence the SQL statement has a syntax error. How can I write it such that it still takes the 'OR' but takes the last 'OR' off?

While Not rs2.EOF
sSql3 = sSql3 & "(trim([PA_Detail].Quality) = " & rs2![QualityXRef] & " OR "
rs2.MoveNext
Wend
sSql = sSql & " AND (" & sSql3 & ")"
 
While Not rs2.EOF
sSql3 = sSql3 & "(trim([PA_Detail].Quality) = " & rs2![QualityXRef] & " OR "
rs2.MoveNext
Wend
sSql3 = left(sSql3, len(sSql3)- 4)
sSql = sSql & " AND (" & sSql3 & ")"

Water is not bad as soon as it stays out human body ;-)
 
sSql3 = vbNullString+


While Not rs2.EOF
If len(sSql3)>0 then sSql3=sSql3 & " OR "
sSql3 = sSql3 & "(trim([PA_Detail].Quality) = " & rs2![QualityXRef]
rs2.MoveNext
Wend
sSql = sSql & " AND (" & sSql3 & ")"


OR


While Not rs2.EOF

sSql3 = sSql3 & "(trim([PA_Detail].Quality) = " & rs2![QualityXRef]
rs2.MoveNext
If not rs2.eof then sSql3=sSql3 & " OR "
Wend
sSql = sSql & " AND (" & sSql3 & ")" [/b][/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top