TRY to CAST

  • russ dalton - Wednesday, April 11, 2018 7:14 AM

    The answer query post isn't the same as the first posted question query.  The 2nd post has an 'ELSE' statement which translates the results to -1.  If you run the query in the answer post, you will get -1 instead of nulls.

    Yep, I got this when I ran it, not the answer posted in the email.  I only looked here because the posted answer looked wrong to me.
    -1
    123
    -1
    20180301
    -1

  • You do not need to use CAST twice!

    SELECT ISNULL(TRY_CAST(Myval AS INT), -1) FROM CastTest;

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

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