Which code segment should you use?

You use Microsoft SQL Server 2012 to develop a database application. Your application sends data to an NVARCHAR(MAX) variable named @var. You need to write a Transact-SQL statement that will find out the success of a cast to a decimal (36,9). Which code segment should you use? select
A. BEGIN TRY
SELECT convert(decimal(36,9), @var) AS Value, ‘True’ AS BadCast
END TRY
BEGIN CATCH
SELECT convert(decimal(36,9), @var) AS Value, ‘False’ AS BadCast
END CATCH
B. TRY(
SELECT convert(decimal(36,9), @var)
SELECT ‘True’ AS BadCast
)
CATCH(
SELECT ‘False’ AS BadCast
)
C. SELECT
CASE
WHEN convert(decimal(36,9), @var) IS NULL
THEN ‘True’
ELSE ‘False’
END
AS BadCast
D. SELECT
IIF(TRY_PARSE(@var AS decimal(36,9)) IS NULL, ‘True’, ‘False’)
AS BadCast

microsoft-exams

Leave a Reply

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.