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

Quick DB String Help Needed

Status
Not open for further replies.

mikecx

Technical User
Jul 9, 2002
215
US
I have 3 things being passed from a form. All need to be checked. The code works if all are left alone, basically set to none. If they aren't it whines. I know it's something simple to do with the syntax but I can't see it.

Code:
curhs = Request.Form("schoolis")
appfine = Request.Form("fneedis")
appneed = Request.Form("needis")

	If curhs <> &quot;anyschool&quot; then
		strSQL1 =  &quot;SELECT * FROM dbo.PCGA WHERE dbo.PCGa.curhs = &quot; & curhs
	ElseIf curhs = &quot;anyschool&quot; then
		strSQL1 = &quot;SELECT * FROM dbo.PCGa WHERE&quot;
	End If
	If appfine <> &quot;Any&quot; and curhs = &quot;anyschool&quot; then
		strSQL2 = strSQL1 + &quot; dbo.PCGa.appfine = &quot; & appfine
	ElseIf appfine <> &quot;any&quot; and curhs <> &quot;anyschool&quot; then
		strSQL2 = strSQL1 + &quot; & dbo.PCGa.appfine = &quot; & appfine
	ElseIf appfine = &quot;Any&quot; then
		strSQL2 = strSQL1
	End If
	If appneed <> &quot;Any&quot; and curhs = &quot;anyschool&quot; and appfine = &quot;Any&quot; then
		strSQL = strSQL2 + &quot; dbo.PCGa.appneed = &quot; & appneed
	ElseIf appneed <> &quot;Any&quot; and curhs <> &quot;anyschool&quot; or appfine <> &quot;Any&quot; then
		strSQL = strSQL2 + &quot; & dbo.PCGa.appneed = &quot; & appneed 
	ElseIf appneed = &quot;Any&quot; then
		strSQL = strSQL2
	Elseif appneed = &quot;Any&quot; and curhs = &quot;anyschool&quot; and appfine = &quot;Any&quot; then
		strSQL = &quot;SELECT * FROM dbo.PCGa&quot;
	End If

thanks
 
Updated a Bit:

Code:
If curhs <> &quot;anyschool&quot; then
		strSQL1 =  &quot;SELECT * FROM dbo.PCGA WHERE dbo.PCGa.curhs = &quot; & curhs
	ElseIf curhs = &quot;anyschool&quot; then
		strSQL1 = &quot;SELECT * FROM dbo.PCGa&quot;
	End If
	If appfine <> &quot;Any&quot; and curhs = &quot;anyschool&quot; then
		strSQL2 = strSQL1 + &quot; WHERE dbo.PCGa.appfine = &quot; & appfine
	ElseIf appfine <> &quot;Any&quot; and curhs <> &quot;anyschool&quot; then
		strSQL2 = strSQL1 + &quot; & dbo.PCGa.appfine = &quot; & appfine
	ElseIf appfine = &quot;Any&quot; then
		strSQL2 = strSQL1
	End If
	If appneed <> &quot;Any&quot; and curhs = &quot;anyschool&quot; and appfine = &quot;Any&quot; then
		strSQL = strSQL2 + &quot; WHERE dbo.PCGa.appneed = &quot; & appneed
	ElseIf appneed <> &quot;Any&quot; and curhs <> &quot;anyschool&quot; or appfine <> &quot;Any&quot; then
		strSQL = strSQL2 + &quot; & dbo.PCGa.appneed = &quot; & appneed 
	ElseIf appneed = &quot;Any&quot; then
		strSQL = strSQL2
	Elseif appneed = &quot;Any&quot; and curhs = &quot;anyschool&quot; and appfine = &quot;Any&quot; then
		strSQL = &quot;SELECT * FROM dbo.PCGa&quot;
	End If
 
Sorry for the quick updates but here's the code that almost works. It works except for the second code block. It appeasr to me to be the same as the first and third but it wont work.

If curhs <> &quot;anyschool&quot; then
strSQL1 = &quot;SELECT * FROM dbo.PCGA WHERE dbo.PCGa.curhs =&quot; & &quot;'&quot; & curhs & &quot;'&quot;
ElseIf curhs = &quot;anyschool&quot; then
strSQL1 = &quot;SELECT * FROM dbo.PCGa&quot;
End If

If appfine <> &quot;Any&quot; and curhs = &quot;anyschool&quot; then
strSQL2 = strSQL1 + &quot; WHERE dbo.PCGa.appfine =&quot; & &quot;'&quot; & appfine & &quot;'&quot;
ElseIf appfine <> &quot;Any&quot; and curhs <> &quot;anyschool&quot; then
strSQL2 = strSQL1 + &quot; & dbo.PCGa.appfine =&quot; & &quot;'&quot;& appfine & &quot;'&quot;
ElseIf appfine = &quot;Any&quot; then
strSQL2 = strSQL1
End If

If appneed <> &quot;Any&quot; and curhs = &quot;anyschool&quot; and appfine = &quot;Any&quot; then
strSQL = strSQL1 + &quot; WHERE dbo.PCGa.appneed =&quot; & &quot;'&quot; & appneed & &quot;'&quot;
ElseIf appneed <> &quot;Any&quot; and curhs <> &quot;anyschool&quot; or appfine <> &quot;Any&quot; then
strSQL = strSQL2 + &quot; & dbo.PCGa.appneed =&quot; & &quot;'&quot; & appneed & &quot;'&quot;
ElseIf appneed = &quot;Any&quot; then
strSQL = strSQL2
End If
 
I fixed that problem, it turned out to be and order of operations mistake but this one still isn't working right. It will work if there is only one selected but not if there are 2 or 3:

Code:
	If curhs <> &quot;anyschool&quot; then
		strSQL1 =  &quot;SELECT * FROM dbo.PCGA WHERE dbo.PCGa.curhs =&quot; & &quot;'&quot; & curhs & &quot;'&quot;
	ElseIf curhs = &quot;anyschool&quot; then
		strSQL1 = &quot;SELECT * FROM dbo.PCGa&quot;
	End If
	
	If appfine <> &quot;Any&quot; and curhs = &quot;anyschool&quot; then
		strSQL2 = strSQL1 + &quot; WHERE dbo.PCGa.appfine =&quot; & &quot;'&quot; & appfine & &quot;'&quot; 
	ElseIf appfine <> &quot;Any&quot; and curhs <> &quot;anyschool&quot; then
		strSQL2 = strSQL1 + &quot; & dbo.PCGa.appfine =&quot; & &quot;'&quot;& appfine & &quot;'&quot;
	ElseIf appfine = &quot;Any&quot; then
		strSQL2 = strSQL1
	End If
	
	If appneed <> &quot;Any&quot; and curhs = &quot;anyschool&quot; and appfine = &quot;Any&quot; then
		strSQL = strSQL1 + &quot; WHERE dbo.PCGa.appneed =&quot; & &quot;'&quot; & appneed & &quot;'&quot;
	ElseIf appneed = &quot;Any&quot; then
		strSQL = strSQL2
	ElseIf appneed <> &quot;Any&quot; and curhs <> &quot;anyschool&quot; or appfine <> &quot;Any&quot; then
		strSQL = strSQL2 + &quot; & dbo.PCGa.appneed =&quot; & &quot;'&quot; & appneed & &quot;'&quot;

	End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top