limit search query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fran7
    New Member
    • Jul 2006
    • 229

    limit search query

    Hi, I have this search query



    Code:
    'search feature
    If Request("SearchWord") <> "" Then
    	strWd=Replace(Request("SearchWord"),"'","''")
    	strSQL="Select PostCardID,DefaultHeadline,CardDescription,DefaultMessage,Author,Artist,gallery,NewImageOne,extratwo,extrathree,NewImageTwo,largeimageseven,NewImageThree,NewImageFour,NewImageFive,NewImageSix,NewImageSeven,NewImageEight,dimensionsseven, "
    	strSQL=strSQL & " ThumbnailURL,AdvancedCard,ThumbnailHTML From tblGreetingPostCards Where Keywords Like '%" & strWD & "%' OR "
    	strSQL=strSQL & " DefaultHeadline Like '%" & strWD & "%' OR "
    	strSQL=strSQL & " CardDescription Like '%" & strWD & "%' OR "
    	strSQL=strSQL & " Author Like '%" & strWD & "%' OR "
    	strSQL=strSQL & " DefaultMessage Like '%" & strWD & "%' "
    	
    	Set connPostCardSoft=Server.CreateObject("ADODB.Connection") 
    	connPostCardSoft.Open PostCardSoftConnectString
    	Set rsCard=Server.CreateObject("ADODB.Recordset")
    	rsCard.CursorLocation = 3
    	rsCard.Open strSQL, connPostCardSoft
       	rsCard.PageSize = 1000
       	intPageCount = rsCard.PageCount
    End If

    I dont want it to return any results from a category so I added

    Code:
    where CategoryID <> " & 60 & "  and Keywords Like '%" & strWD & "%' OR "
    to the query but it still returns results for all categories. Although its looking for words in particular fields I presumed this would make it ignore those field in that category but it doesnt.
    Any ideas would be great.
    Thanks
    Richard
  • DrBunchman
    Recognized Expert Contributor
    • Jan 2008
    • 979

    #2
    Hi Richard,

    I suspect the problem is the lack of brackets surrounding your OR statements.

    Remember that

    WHERE A=1 AND B=2 OR B=3

    is different from

    WHERE A=1 AND (B=2 OR B=3)

    Hope this helps,

    Dr B

    Comment

    • fran7
      New Member
      • Jul 2006
      • 229

      #3
      Thanks, worked a treat.
      Richard

      Comment

      Working...