Brain teaser- can anyone figure this out.

Results 1 to 2 of 2

Thread: Brain teaser- can anyone figure this out.

  1. #1
    Join Date
    Dec 1969

    Default Brain teaser- can anyone figure this out.

    I have a table with a date stored in 3 fields: r_month, r_day and r_year. I want to pull out the ones only that match todays date, plus a specified amount of days (r_before). The only problem is that (obviously) the datepart(d,getdate()) + r_before doesn&#039t recognize when there is a new month, so it adds the r_before, even if it&#039s the end of the month. Can anyone think of a better way to do this?<BR>SELECT Store_Customers.First_Name, Store_Customers.Last_Name FROM Store_Customers WHERE (datepart(m,getdate())=r_month) AND datepart(d,getdate()) + r_before=r_day AND datepart(yyyy,getdate())=r_year

  2. #2
    Join Date
    Dec 1969
    Los Angeles, CA

    Default Let me get this straight

    you dont want it to add the days if it is going to retrieve records from the next month??<BR><BR>that is if you wnat ot add 3 days and today if the 29 then dont add only add upto 30 if it is 15 and you wnat to add 3 days then go ahead and add it??<BR><BR>If that is what you wnat to do then the only thing i can think of is dynamic SQL and i would suggest you write an SP to solve it<BR>

Posting Permissions

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