469,270 Members | 1,784 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

limit search query

229 100+
Hi, I have this search query



Expand|Select|Wrap|Line Numbers
  1. 'search feature
  2. If Request("SearchWord") <> "" Then
  3.     strWd=Replace(Request("SearchWord"),"'","''")
  4.     strSQL="Select PostCardID,DefaultHeadline,CardDescription,DefaultMessage,Author,Artist,gallery,NewImageOne,extratwo,extrathree,NewImageTwo,largeimageseven,NewImageThree,NewImageFour,NewImageFive,NewImageSix,NewImageSeven,NewImageEight,dimensionsseven, "
  5.     strSQL=strSQL & " ThumbnailURL,AdvancedCard,ThumbnailHTML From tblGreetingPostCards Where Keywords Like '%" & strWD & "%' OR "
  6.     strSQL=strSQL & " DefaultHeadline Like '%" & strWD & "%' OR "
  7.     strSQL=strSQL & " CardDescription Like '%" & strWD & "%' OR "
  8.     strSQL=strSQL & " Author Like '%" & strWD & "%' OR "
  9.     strSQL=strSQL & " DefaultMessage Like '%" & strWD & "%' "
  10.  
  11.     Set connPostCardSoft=Server.CreateObject("ADODB.Connection") 
  12.     connPostCardSoft.Open PostCardSoftConnectString
  13.     Set rsCard=Server.CreateObject("ADODB.Recordset")
  14.     rsCard.CursorLocation = 3
  15.     rsCard.Open strSQL, connPostCardSoft
  16.        rsCard.PageSize = 1000
  17.        intPageCount = rsCard.PageCount
  18. End If

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

Expand|Select|Wrap|Line Numbers
  1. 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
Jun 26 '08 #1
2 1618
DrBunchman
979 Expert 512MB
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
Jun 26 '08 #2
fran7
229 100+
Thanks, worked a treat.
Richard
Jun 26 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.