|
Subject:
|
dynamic MySQL hit
|
|
Posted By:
|
crmpicco
|
Post Date:
|
6/14/2005 4:02:54 AM
|
How can i make this dynamic as not all fields will be available everytime as the variable values are coming from a form field.
set rs1=con.execute("select * from net_fares where company_id = '"& company_id &"' and contract_id = '"& contract_id &"' and dep like '%"& dep &"%' and arr like '%"& arr &"%' and via like '%"& via &"%' and season = '%"& season &"%' and cabin = '%"& cabin &"%' and zone = '%"& zone &"%' and region = '%"& region &"%'")
www.crmpicco.co.uk www.crmpicco.co.uk.tt www.milklemonadechocolate.uk.tt www.griswolds.uk.tt www.piccosmini.co.uk.tt www.morton.uk.tt
|
|
Reply By:
|
ChrisScott
|
Reply Date:
|
6/17/2005 7:39:47 AM
|
Not exactly sure what you mean, but if the variables company_id etc are coming from a form field, you could build the query up before executing, e.g.:
Dim query: query = "SELECT * FROM net_fares "
Dim where: where = ""
If company_id <> "" Then
where = where & "AND companyid = '" & company_id & "' "
End If
... process other fields ...
If where <> "" Then
' add the where clause without the initial "AND"
query = query & Mid(where, 5)
End If
Set rs1 = con.Execute(query, , adCmdText)
BTW, why not split your code onto separate lines using "_" if lines are very long, makes it easier to read and not so hard to reply to on the forums as well!
HTH,
Chris
|