Stored Procedure: Date calculations using Datediff

  • Please excuse my igonorance as I am new to SQL. My question is this: there is a stored procedure that claculates the remaining payments in a lease using the datediff function. datediff(month,@as_of_date, #lease_scheds.end_date) remaining term

    Unfortunately, it returns negative values that we would like to be = to 0. It seems like it should be easy if I only knew more about stored procedures!! How would I acomplish this?

  • Try this,

    CASE

    WHEN datediff(month,@as_of_date, #lease_scheds.end_date) < 0 THEN 0 ELSE datediff(month,@as_of_date, #lease_scheds.end_date)

    END

    By using case I tell the value to be 0 when less than 0 otherwise print the value.

    "Don't roll your eyes at me. I will tape them in place." (Teacher on Boston Public)

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

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