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!

Numeric Default Value In Recordset 1

Status
Not open for further replies.

djcampos

Programmer
May 12, 2005
15
US
I'm trying to create a search form with two text boxes. The first is a Work Order ID text box. The second is an Email text box. My SQL looks like this:

SELECT *
FROM dbo.Request2
WHERE Order_ID = 'varID' OR Email LIKE 'varEmail'

Name Default Value Run-time Value

varID 0 Request.Form("txtID")
varEmail % Request.Form("txtEmail")

My question is concerning the default value for the varID variable. This is datatype INT in the database but I want to put in a special character like % but I keep getting an error because that percent sign is not numeric. Is there something else that I can put in it's place? This error occurs when someone wants to search only by Email and leaves the Work Order ID text box blank. Any suggestions would be appreciated.
 
I would use an "IF" to create the Query before sending it to be executed. This IF would check if there is something in the Id text box, and create a query accordingly.

Since I don't know what language your using, this is going to be very generic:(pseudocode)
Code:
if(Order_Id is NULL)
{
query="SELECT *
FROM dbo.Request2
WHERE Email LIKE 'varEmail'"
}
else if(varEmail is NULL)
query=SELECT *
FROM dbo.Request2
WHERE Order_ID = 'varID'
}
else  if(Order_ID is NULL and varEmail is NULL)
{
echo out:  need at least 1 field for search.
}
else {
query=SELECT *
FROM dbo.Request2
WHERE Order_ID = 'varID' OR Email LIKE 'varEmail'
}


It checks the textboxes to see whih ones have values, and creates the query accordingly, if the ID is not filled in, thn the query only looks for the email. and viceversa. If nothing has a vlue then it returns an error.

Hope this helps

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Good idea vacunita, it would not be hard to do something similar in a javascript function that was called on form submission. As you say it depends on the language being used.

Cheech

[Peace][Pipe]
 
Exactly, and that way, you can even add searchable fields in the near future by adding if statements, with the appropriate query without to much hassle.

I'm glad I could help.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top