• wendy elizabeth (2/11/2016)


    I have the following t-sql 2012, which is the following:

    DECLARE @endYear varchar(04) = 2016

    select convert(smalldatetime, ('07/31/' + convert(char(02), @endYear - 1)))

    select convert(smalldatetime, '08/01/' + @endYear )

    that is having a conversion error.

    I want one select statement to be 07/31/2015 and the other date to be

    08/01/2016 in a smalldatetime format.

    Thus can you show me the sql to accomplish my goal?

    Always check what are you actually trying to convert:

    select '07/31/' + convert(char(02), @endYear - 1)

    And it's desirable to use style for datetime conversions.

    _____________
    Code for TallyGenerator