Select Statement

Discussion in 'Databases - SQL Server 2008 / MySQL' started by Piercy, Aug 15, 2006.

  1. Piercy Rather crap web designer

    Trying to do a Select statement where I filter on two different fields.

    The first part (MMCol Param) is simple a filter send from the previous page i have then added an additonal filter that is predefined.

    Code is:

    Set rsGallery = Server.CreateObject("ADODB.Recordset")
    rsGallery.ActiveConnection = MM_railway_STRING
    rsGallery.Source = "SELECT * FROM TBGallery WHERE CatergoryID = '" + Replace(rsGallery__MMColParam, "'", "''") + "' WHERE PICTUREINCLUDE = YES ORDER BY Picturedate DESC"
    rsGallery.CursorType = 0
    rsGallery.CursorLocation = 2
    rsGallery.LockType = 1
    rsGallery.Open()


    Section in RED is were I have amended the code (all the rest done with dreamweaver).

    Guess what - it doesn't work!

    Any ideas?:unsure:
  2. Carl Shepherdson Proprietor

    Looking at it out of context isn't easy (especially with no error given) but assuming that YES is a string, it should be surrounded in single quotes, i.e:

    Code:
    + "' WHERE PICTUREINCLUDE = 'YES' ORDER BY Picturedate DESC"  
  3. To me it looks like you are including the WHERE clause in your statement twice (once before the CategoryID condition and again for the PictureInclude condition.

    Try changing it to this:

    rsGallery.Source = "SELECT * FROM TBGallery WHERE CatergoryID = '" + Replace(rsGallery__MMColParam, "'", "''") + "' AND PICTUREINCLUDE = 'YES' ORDER BY Picturedate DESC"
  4. sladmin CSNM Reseller

    Just a quick note, make sure you have all the quotes right especially if you hand wrote the statement.

    Did you use dreamweaver? If so can you take a screenshot of the Command box?

    Good Luck!

Share This Page