Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 5th, 2005, 11:54 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 240
Thanks: 0
Thanked 1 Time in 1 Post
Default Having trouble with AND, iCounter in SQL

I think it the iCounter that's not placed properly. I often get and extra "AND". I erase the "AND" and search something else and then there is a lack of "AND".
Code:
    rs.PageSize = RECORDS_PER_PAGE
    rs.CacheSize = 5
    rs.CursorLocation = adUseClient
    Dim SQL
    Dim number
    Dim hInput
    Dim hOutput
    Dim iCounter
    Dim Keyword     ' Keyword for search
    Dim Keywordb
    Dim Keywordc
    Dim Keywordd
    Dim Keyworde
    Dim Keywordf
    Dim spoke
    Dim aRecTypes
    Dim iLoopCount
    Dim recordType

        ' Let's see what user wants to search for today :)
    Keyword = Trim(Request.QueryString("Keyword"))
    Keywordb = Trim(Request.QueryString("Keywordb"))
    Keywordc = Trim(Request.QueryString("Keywordc"))
    Keywordd = Trim(Request.QueryString("Keywordd"))
    Keyworde = Trim(Request.QueryString("Keyworde"))
    Keywordf = Trim(Request.QueryString("Keywordf"))
    spoke = Request.Querystring("spoke")
    number = Request.QueryString("number")
    hInput = Request.QueryString("hInput")
    hOutput = Request.QueryString("hOutput")
    recordType = Request.QueryString("hebrewbibletable.recordType")
    iCounter = 0

SQL= "SELECT * "
SQL = SQL & " FROM hebbooktable INNER JOIN hebrewbibletable "
SQL = SQL & " ON hebbooktable.book = hebrewbibletable.book "
SQL = SQL & " WHERE "

'    SQL = "SELECT * FROM 2 WHERE "

If Keyword <> "" Then
  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If
    SQL = SQL & "text_data LIKE '%" & Keyword & "%' "
      iCounter = iCounter + 1
End If 
If Keywordb <> "" Then
  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If
    SQL = SQL & "text_data LIKE '%" & Keywordb & "%' "
      iCounter = iCounter + 1
End If 
If Keywordc <> "" Then
  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If
    SQL = SQL & "text_data LIKE '%" & Keywordc & "%' "
      iCounter = iCounter + 1
End If 
If Keywordd <> "" Then
  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If
    SQL = SQL & "text_data LIKE '%" & Keywordd & "%' "
      iCounter = iCounter + 1
End If 
If Keyworde <> "" Then
  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If
    SQL = SQL & "text_data LIKE '%" & Keyworde & "%' "
      iCounter = iCounter + 1
End If 
If Keywordf <> "" Then
  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If
    SQL = SQL & "text_data LIKE '%" & Keywordf & "%' "
      iCounter = iCounter + 1
End If 

If   request.QueryString("book_spoke")="Book_Spoke" then

  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If
  SQL = SQL & "book_spoke LIKE '" & spoke & "'"
  iCounter = iCounter + 1
end if

If   request.QueryString("chapter_spoke")="Chapter_Spoke" then

  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If

  SQL = SQL & "chapter_spoke LIKE '" & spoke & "'"

  iCounter = iCounter + 1

end if

If   request.QueryString("verse_spoke")="Verse_Spoke" then

  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If

  SQL = SQL & "verse_spoke LIKE '" & spoke & "'"

  iCounter = iCounter + 1

end if


'If number <> "" Then

If   request.QueryString("hebbooktable.book")="yes" then

  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If
  SQL = SQL & "hebbooktable.book LIKE '" & number & "'"
  iCounter = iCounter + 1
end if

If   request.QueryString("chapter")="yes" then

  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If

  SQL = SQL & "chapter LIKE '" & number & "'"

  iCounter = iCounter + 1

end if

If   request.QueryString("verse")="yes" then

  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If

  SQL = SQL & "verse LIKE '" & number & "'"

  iCounter = iCounter + 1

end if
If   request.QueryString("bookchapter")="yes" then

  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If

  SQL = SQL & "hebrewbibletable.book & chapter LIKE '%" & number & "%'"

  iCounter = iCounter + 1

end if

If   request.QueryString("chapterverse")="yes" then

  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If

  SQL = SQL & "chapter & verse LIKE '%" & number & "%'"

  iCounter = iCounter + 1

end if
If   request.QueryString("bookchapterverse")="yes" then

  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If

  SQL = SQL & "hebrewbibletable.book & chapter & verse LIKE '%" & number & "%'"

  iCounter = iCounter + 1

end if

If Trim(Request.QueryString("recordType")) <> "" Then
  aRecTypes = Split(Request.QueryString("recordType"), ",")
  If IsArray(aRecTypes) Then
        SQL = SQL & " AND ("
    For iLoopCount = 0 To UBound(aRecTypes)
      If iLoopCount <> 0 Then
          SQL = SQL & " OR "
      End If
          SQL = SQL & "recordType = '" & trim(aRecTypes(iLoopCount)) & "'"
    Next
  End If
      SQL = SQL & ")"
iCounter = iCounter + 1
End If

'End If
If hInPut <> "" Then
  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If

  SQL = SQL & "text_data LIKE '%" & hInPut & "%'"

  iCounter = iCounter + 1

end if

If hOutPut <> "" Then

  If iCounter > 0 Then
    SQL = SQL & " AND "
  End If

  SQL = SQL & "book & chapter & verse LIKE '%" & hOutPut & "%'"

'  iCounter = iCounter + 1

end if

SQL = SQL & " ORDER BY id ASC "
Martial Law 9/11 Rise of the Police State is now available! Visit our Martial Law movie section for complete info (click here), or order now by clicking the button below or by calling 888-253-3139
http://www.infowars.com/martial_law_911.htm





Similar Threads
Thread Thread Starter Forum Replies Last Post
Trouble executing SQL statement turbo_rabbit ASP.NET 1.0 and 1.1 Basics 13 July 6th, 2005 01:31 PM
Trouble executing SQL statement turbo_rabbit Classic ASP Databases 6 July 6th, 2005 01:30 PM
Trouble with SQL statement jsanders ASP.NET 1.0 and 1.1 Basics 1 May 24th, 2005 03:11 PM
having trouble installing MSDE /SQL kenh SQL Server 2000 2 April 1st, 2005 02:45 AM
SQL Trouble mrideout BOOK: Beginning ASP.NET 1.0 1 September 30th, 2004 12:24 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.