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

OBF Build SQL String for function

Status
Not open for further replies.

stevecrowhurst

IS-IT--Management
Oct 23, 2003
1
GB
Could you guys run your eye over the function below and give me a few tips on the WHERE clause.
I'm trying to construct a QBF and I'm fighting a very stringent deadline. Thanks for the help.

Function BuildSQLString(ByRef strSQL As String) As Boolean

Dim strSELECT As String
Dim strFROM As String
Dim strWHERE As String

strSELECT = "SELECT s.*.*" 'set the columns to return results from
'(all columns in this case)
'set an alias "h" for HRBaseTbl
strFROM = "FROM HRBaseTbl As h "

If chkFirstNameID Then
'check for 2nd or more WHERE term
If strWHERE <> &quot; &quot; Then strWHERE = strWHERE & &quot; AND &quot;
strWHERE = strWHERE & &quot;h.HRID = &quot; & cboFirstNameID
End If

If chkSurnameID Then
'check for 2nd or more WHERE term
If strWHERE <> &quot; &quot; Then strWHERE = strWHERE & &quot; AND &quot;
strWHERE = strWHERE & &quot;h.HRID = &quot; & cboSurnameID
End If

strSQL = strSELECT & strFROM
If strWHERE <> &quot; &quot; Then strSQL = strSQL & &quot;WHERE &quot; & strWHERE

BuildSQLString = True
End Function
 
Not Really strong in sql but
i think when building the sql you will need to use something
like this
strWHERE = strWHERE & &quot;((h.HRID) = &quot; & cboSurnameID & &quot;)&quot;

and also when you have finished adding all your &quot;And&quot; then
you will need a extra &quot;;)&quot; at the end of the string
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top