It Was Written
I was a bit surprised by this, because I thought the whole point of these new functions was to avoid errors like this.
SELECT oops = TRY_CONVERT(uniqueidentifier, 1); GO SELECT oops = TRY_CAST(1 AS uniqueidentifier); GO
Both of these selects will throw the same error message:
Msg 529, Level 16, State 2, Line 2
Explicit conversion from data type int to uniqueidentifier is not allowed.
Which, you know, fine. I get that limitation of an explicit cast or convert, but why not just throw a NULL like other cases where the expression isn’t successful?
Thanks for reading!
If this is the kind of SQL Server stuff you love learning about, you’ll love my training. I’m offering a 75% discount on to my blog readers if you click from here. I’m also available for consulting if you just don’t have time for that and need to solve performance problems quickly.