Display Data Based on two date fields

  • Hello Guys,

    News rotator and I am writing the query for it.. what i want to do is filter out news based on two date columns and todays date..

    I need to only display data where FinishDate is not greater than todays date.. is this possible at all?

    SELECT CMA_projects.news_data_0_system.NewsSystemID, CONVERT(nvarchar, CMA_projects.news_data_0_system.NewsDate, 103) AS NewsDate,

    CMA_projects.news_lut_category.NewsCategory, CMA_projects.news_lut_title.NewsTitle, CMA_projects.news_data_0_system.NewsDetails,

    CMA_projects.news_data_0_system.News_EditedBy, CMA_projects.news_data_0_system.News_EditedDate, CMA_projects.news_data_0_system.DisplayNews,

    CMA_projects.news_data_0_system.CMAID, CMA_projects.news_data_0_system.News_EditedDate + 3 AS FinishDate,

    CMA_projects.news_data_0_system.NewsHyperlink, CMA_projects.news_data_0_system.NewsSnapshot, CMA_projects.news_data_0_system.NewsSnapshot2

    FROM CMA_projects.news_data_0_system LEFT OUTER JOIN

    CMA_projects.news_lut_title ON CMA_projects.news_data_0_system.NewsTitleID = CMA_projects.news_lut_title.NewsTitleID LEFT OUTER JOIN

    CMA_projects.news_lut_category ON CMA_projects.news_data_0_system.NewsCategoryID = CMA_projects.news_lut_category.NewsCategoryID

    WHERE (CMA_projects.news_data_0_system.DisplayNews = 1)

  • Add a where clause like..

    WHERE (CMA_projects.news_data_0_system.News_EditedDate + 3) < Convert(varchar(8),GetDate(),112)

    I think that should be enough for you...

    Mohit.

    [font="Arial"]---

    Mohit K. Gupta, MCITP: Database Administrator (2005), My Blog, Twitter: @SQLCAN[/url].
    Microsoft FTE - SQL Server PFE

    * Some time its the search that counts, not the finding...
    * I didn't think so, but if I was wrong, I was wrong. I'd rather do something, and make a mistake than be frightened and be doing nothing. :smooooth:[/font]

    How to ask for help .. Read Best Practices here[/url].

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply