March 1, 2016 at 10:17 pm
Comments posted to this topic are about the item TRY_CONVERT large numbers
March 2, 2016 at 12:25 am
This was removed by the editor as SPAM
March 2, 2016 at 12:48 am
Nice question Steve, a very good reminder i almost got it wrong but the inner voice came at the right time 😉
March 2, 2016 at 1:32 am
The strange thing is that this code returns NULL using NVARCHAR(1)
SELECT TRY_CONVERT(NVARCHAR(1), 234523)
March 2, 2016 at 3:08 am
When execute below code then error message come, not * (star).
SELECT TRY_CONVERT(VARCHAR(1), 234523)
An error
Msg 195, Level 15, State 10, Line 1
'VARCHAR' is not a recognized built-in function name.
When execute below code then answer come as *.
SELECT CONVERT(VARCHAR(1), 234523)
Result
*
So, you cut wrong point.
March 2, 2016 at 3:12 am
A nice, simple question to start the day. Thanks.
March 2, 2016 at 3:13 am
When execute below code then error message come, not * (star).
SELECT TRY_CONVERT(VARCHAR(1), 234523)
An error
Msg 195, Level 15, State 10, Line 1
'VARCHAR' is not a recognized built-in function name.
When execute below code then answer come as *.
SELECT CONVERT(VARCHAR(1), 234523)
Result
*
So, you cut wrong point.
What's the version of sqlserver?
March 2, 2016 at 3:18 am
SQL Server 2012
March 2, 2016 at 3:18 am
Got the same result, an error
Tried SELECT TRY_CINVERT(FLOAT, 234523) and got
Msg 195, Level 15, State 10, Line 2
'TRY_CONVERT' is not a recognized built-in function name.
March 2, 2016 at 3:18 am
Carlo Romagnano (3/2/2016)
When execute below code then error message come, not * (star).
SELECT TRY_CONVERT(VARCHAR(1), 234523)
An error
Msg 195, Level 15, State 10, Line 1
'VARCHAR' is not a recognized built-in function name.
When execute below code then answer come as *.
SELECT CONVERT(VARCHAR(1), 234523)
Result
*
So, you cut wrong point.
What's the version of sqlserver?
SQL Server 2012
March 2, 2016 at 3:23 am
jiken (3/2/2016)
When execute below code then error message come, not * (star).SELECT TRY_CONVERT(VARCHAR(1), 234523)
An error
Msg 195, Level 15, State 10, Line 1
'VARCHAR' is not a recognized built-in function name.
When execute below code then answer come as *.
SELECT CONVERT(VARCHAR(1), 234523)
Result
*
So, you cut wrong point.
Try running it in a database with the compatibility level set to 110 (SQL Server 2012) or higher.
March 2, 2016 at 3:24 am
patrick.mccausland (3/2/2016)
Got the same result, an errorTried SELECT TRY_CINVERT(FLOAT, 234523) and got
Msg 195, Level 15, State 10, Line 2
'TRY_CONVERT' is not a recognized built-in function name.
Try running it on SQL Server 2012 or higher.
(As indicated in the question)
March 2, 2016 at 3:27 am
Mea culpa,
I AM on SQL 12 server, however, I was in a database running at compatibility level 9.
Changed to 12 and got the expected result.
March 2, 2016 at 3:28 am
Nice catch, Hugo. The first one with VARCHAR being the problem is one I still don't get, but the TRY_CONVERT bring the problem makes sense.
March 2, 2016 at 3:45 am
Ed Wagner (3/2/2016)
Nice catch, Hugo. The first one with VARCHAR being the problem is one I still don't get, but the TRY_CONVERT bring the problem makes sense.
TRY_CONVERT was introduced as a reserved keyword in compat level 110. Older compat levels do not recognise it as a keyword, so they assume it's a user-defined object.
The result is that SELECT TRY_CONVERT(varchar(1), 1234) is evaluated just the same way as for instance SELECT asfsd(rtrt(), 123) - and apparently the evaluation starts at the innermost level because this raises an error about rtrt not being recognised; replace this with just a number or something and then you'll get an error about asfsd.
(In compat 110 and up, SQL Server knows that TRY_CONVERT is special in that the first parameter is a data type name; for "normal" functions varchar(1) is never a valid argument)
Viewing 15 posts - 1 through 15 (of 30 total)
You must be logged in to reply to this topic. Login to reply