YTD as a default value in a Report

  • Greetings all! I'm new to writing SQL reports so I apologize in advance if this is a beginners question.

    I'm writing a report where I've selected records based on a datetime colum using:

    select closedate from between @begin and @end

    I've defaulted the @end value to be "=Now" and that yields what I expect it to (the current date and time), but I cannot figure out how to define the @begin parameter to always default to 1/1 of the current year. Can anyone point me in the right direction for this? I'd like these to be default values so I can schedule them to run automatically and I think hard coding this in the SQL statement would just be silly.

    Many thanks in advance!

    -Sam

  • Hi Sam,

    Here's a snippet of code I've used in the past for just such a situation:

    =cdate(Month(Today) & "/01/" & Year(Today))

    this would use the current month and year so 04/01/2007

    what you want is:

    =cdate( "01/01/" & Year(Today)) and that should do the trick.

    Give it a try and let me know the results.

    -hawkeyeboy

  • Perfect! That was exactly what I was looking for. Many thanks!

    -Sam

  • No problem Sam. Glad it worked.

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

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