Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TRY_CAST is not a recognized built-in function name

I have a puzzle with regards to the behavior of the SQL Server Management Studio. I am connected to a SQL Server database - version:

Microsoft SQL Server 2014 (SP1-CU3) (KB3094221) - 12.0.4427.24 (X64) 
    Oct 10 2015 17:18:26 
    Copyright (c) Microsoft Corporation
    Enterprise Edition (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)

When I run the following query from management studio, it returns me the correct output.

SELECT TRY_CAST('ax' AS decimal)

SELECT TRY_CAST('4.0' as decimal)

However the built-in editor gives me a message saying this function is not recognized.

Built-In Function

Edited to Add: Sql Server Management Studio version. SQL Server Management Studio 2014

like image 293
abhi Avatar asked Dec 16 '16 15:12

abhi


2 Answers

It is available from sql server 2012. Check

select @@version

Also check the compatibility mode of the database

select name, compatibility_level from sys.databases

If compatibility mode is less that 110 then make it to >=110 by using alter database

alter database yourdatabasename set compatibility_level = 120
like image 129
Kannan Kandasamy Avatar answered Sep 21 '22 12:09

Kannan Kandasamy


It's just an intellisense error. For some reason MS haven't included try_cast in SSMS 2014, although it's recognised as a valid function in SSMS 2016.

like image 40
Gareth Lyons Avatar answered Sep 20 '22 12:09

Gareth Lyons