Getting Values from start and end dates

  • Hello All,
    I have a table with the following columns “FMonth”, “FYear”, “Customer_Name”
    Values for FMonth are 1,2,3,4,5,6,7,8,9,10,11,12
    Values for FYear are “2015”, “2016” and 2017
    I’m creating a report where I want have Parameter for StartDate and EndDate. For example startdate = 1/2015 and enddate = 1/2017
    Is there anyway to should data between those dates? Maybe I need to concat month and year into a single column?

  • Unfortunately, the int type isn't really designed to be used as a date field. When you do, you end up having problems with this. Personally, I would add a column as a proper date field. Otherwise a computed column would work, and pass proper dates. For example:
    ALTER TABLE [YouTable] ADD FDATE AS DATEADD(MONTH,FMONTH - 1, DATEADD(YEAR, FYear - 2000, '20000101'));

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • When working with date ranges, it's best if everything is expressed as dates.  If you are going to use integers or strings to represent (partial) dates, they should be in YYYYMMDD format, because that is the only format where the order matches a true date order.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

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

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