Results 1 to 3 of 3

Thread: Ampersand Breaks Query

  1. #1
    Join Date
    Jan 2010
    Posts
    1

    Ampersand Breaks Query

    Folks,
    I have a query I am using in a Classic ASP page against an SQL Server. The query works fine except when one of the values in the WHERE clause contains an ampersand.

    For example, this returns zero results:

    Code:
    Select NewsItem.NewsItemID, NewsItem.NewsTitle, NewsItem.URL, NewsItem.Published, 
    NewsItem.PublishDate, StoryType.StoryTypeName, PublishLocation.Publishlocation, 
    SiteSelection.CategoryName, SiteSelection.SubCategoryName, NewsItemApproval.Approved
    FROM NewsItem INNER Join SiteSelection ON NewsItem.NewsItemID = SiteSelection.NewsItemID
    LEFT OUTER JOIN NewsItemApproval ON SiteSelection.SortID = NewsItemApproval.SiteSelID
    INNER JOIN StoryType ON NewsItem.StoryTypeID = StoryType.StoryTypeID INNER JOIN
    PublishLocation ON SiteSelection.PublishLocation = PublishLocation.PublishLocationID
    WHERE NewsItem.[Function]='EH&S' AND (NewsItem.PublishDate <= CONVERT(DATETIME, 
    '1/6/2010', 101)) order by PublishDate desc, NewsTitle;
    This is how the value is represented in the actual database, i.e., it's not entered as "EH&amp;S". However, I did try the query using EH&amp;S and it still does not work.

    Any ideas what I need to modify to make this work when some of the WHERE clause terms contain ampersands?

    Thanks for any insight or assistance!

  2. #2
    Join Date
    Sep 2002
    Posts
    5,938
    May need escape character.

  3. #3
    Join Date
    Jan 2010
    Posts
    37
    I agree, it sounds like a special character violation. If you put the query in something like query analyzer or SSMS what do you get?

    Does it work if you replace the & with something like CHAR(38) ?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •