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&S". However, I did try the query using EH&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!