select case statement

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

    select case statement

    Hi I have this query.

    Code:
    lngCategoryID=CLng(Request("CategoryID"))
    If lngCategoryID <> "" And lngCategoryID <> 0 Then
    
    	Set connPostCardSoft=Server.CreateObject("ADODB.Connection") 
    	connPostCardSoft.Open PostCardSoftConnectString
    	Set rsCard=Server.CreateObject("ADODB.Recordset")
    	rsCard.CursorLocation = 3
        SQLQuery="Select postcardid,DefaultHeadline,CardDescription,gallery,DefaultMessage,extrathree,Author,Artist,tip,NewImageOne,"
        SQLQuery= SQLQuery & "NewImageTwo,titleimagesix,largeimageseven,ThumbnailURL,"
        SQLQuery= SQLQuery & "SUM(tblLinkTrackerLog.hit_count) AS totalhits  From tblGreetingPostCards  LEFT OUTER JOIN "
        SQLQuery= SQLQuery & "tblLinkTrackerLog ON "
        SQLQuery= SQLQuery & "tblGreetingPostCards.postcardid = tblLinkTrackerLog.link_id "
        SQLQuery= SQLQuery & "Where CategoryID=" & Clng(lngCategoryID) & " "
        SQLQuery= SQLQuery & "GROUP BY postcardid,DefaultHeadline,CardDescription,gallery,DefaultMessage,extrathree,Author,Artist,tip,NewImageOne,"
        SQLQuery= SQLQuery & "NewImageTwo,titleimagesix,largeimageseven,ThumbnailURL "
        SQLQuery= SQLQuery & "ORDER BY SUM(tblLinkTrackerLog.hit_count) "
        rsCard.Open SQLQuery, connPostCardSoft
       	rsCard.PageSize = 100
       	intPageCount = rsCard.PageCount
       	
       	If rsCard.EOF=True Then
    		response.redirect "./"
           Response.End
    	End If
    End If

    It works fine. Trouble is I want for search engine optimisation it not to throw up an error on the page when the page is visited without the query in the address, for example
    www.mysite.com/directory.asp
    www.mysite.com/directory.asp?c ategoryid=55
    at the moment i get this error

    Code:
    icrosoft VBScript runtime error '800a01a8' 
    Object required: '' 
    
    /directorycontentalt.asp, line 156
    when the page is served just www.mysite.com/directory.asp


    It has been suggested to me that I should write something along these lines.
    select case categoryID
    case 1 : showthem page1
    case 2 : showthem page2
    case 3 : showthem page3
    case 4 : showthem page4
    case else : showthem page0
    end select

    but I dont know how or where to write it. Any pointers would be great.
    Thanks
    Richard
  • Krandor
    New Member
    • Aug 2008
    • 50

    #2
    When lngCategoryID does not have a value, you should just have some generic html page with your keywords so the search bots will be happy.

    If you are getting an error message, it means that your filtering:
    Code:
    If lngCategoryID <> "" And lngCategoryID <> 0 Then
    is not working. Theoretically, it should just ignore your whole If statement and do nothing.

    Personally, I use If Len(lngCategory ID)> 0 to test for empty variables. This works on both numerics and strings.

    Try that and see if it works for you.

    Comment

    • fran7
      New Member
      • Jul 2006
      • 229

      #3
      Thanks Krandor,
      That worked great
      Richard

      Comment

      • jhardman
        Recognized Expert Specialist
        • Jan 2007
        • 3405

        #4
        Originally posted by Krandor
        Personally, I use If Len(lngCategory ID)> 0 to test for empty variables. This works on both numerics and strings.
        Thanks for your suggestion. I tend to use
        Code:
        <> ""
        but I haven't been fully satisfied with it, yours looks like a better idea.

        Jared

        Comment

        Working...