Date Selection

  • Hi Guys!

    can you help me...

    1) what would be the condition if i want to get all transactions dates last year except this year?

    2) what would be the condition if i want to get all transaction dates last year but the same period this year?

    a comparison of this year Jan 2003 transaction versus the transaction last Jan 2002 ...

    Thanks

    lhavn

  • This should get you started:

    DECLARE @Year INT

    DECLARE @Month TINYINT

    SET @Year = 2003

    SET @Month = 1

    SELECT * FROM TransTable

    WHERE DatePart(yy, TransDate) = @Year

    AND DatePart(mm, TransDate) = @Month

    SELECT * FROM TransTable

    WHERE DatePart(yy, TransDate) = @Year - 1

    AND DatePart(mm, TransDate) = @Month

  • Jpipes,

    would it be possible without "Declare Statemet"

  • Jpipes,

    thanks!

    i've done using the declare statement ...

    one more thing ...

    i try to declare MonthFrom and MonthTo to show the whole year last year ... but the result is zero (0) ...

    can't do it ...

    any idea?

    thanks

    lhavn

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

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