• Luis Cazares (7/30/2015)


    yb751 (7/29/2015)


    Luis Cazares (7/29/2015)


    You conversion won't help as it will only truncate the string. It will basically do the same as the LEFT() function. Another problem it that 111 is not the correct format for this problem and most of the times might not be the best option as it is language dependant.

    I used '111' out of habit as it was a common requirement at my old workplace. As per the OP's requirement it should be '126'. Not sure why my conversion "won't help".

    OMG!!! LOL...now I know what you mean. At first I thought you were crazy until I realized my mistake. Originally when I had written out my code locally I had done so by declaring it as a DATETIME. I know this because I still had it open in one of my tabs at least before I decided to change it using a table.

    DECLARE @testDate DATETIME = '2015-07-28 00:00:00'

    --BEFORE

    SELECT @testDate

    --AFTER

    SELECT CONVERT(VARCHAR(10), @testDate, 111)

    Obviously the conversion worked fine for me then. The funny thing is in my final code I did create the table as a VARCHAR.

    Thanks for the clarification otherwise I would never have known what you meant. 🙂


    SELECT quote FROM brain WHERE original = 1
    0 rows returned