exam questions

Exam 70-761 All Questions

View all questions & answers for the 70-761 exam

Exam 70-761 topic 1 question 39 discussion

Actual exam question from Microsoft's 70-761
Question #: 39
Topic #: 1
[All 70-761 Questions]

Note: This question is part of a series of questions that use the same or similar answer choices. An answer choice may be correct for more than one question in the series. Each question is independent of the other questions in this series. Information and details provided in a question apply only to that question.
You have a table named AuditTrail that tracks modifications to data in other tables. The AuditTrail table is updated by many processes. Data input into AuditTrail may contain improperly formatted date time values. You implement a process that retrieves data from the various columns in AuditTrail, but sometimes the process throws an error when it is unable to convert the data into valid date time values.
You need to convert the data into a valid date time value using the en-US format culture code. If the conversion fails, a null value must be returned in the column output. The conversion process must not throw an error.
What should you implement?

  • A. the COALESCE function
  • B. a view
  • C. a table-valued function
  • D. the TRY_PARSE function
  • E. a stored procedure
  • F. the ISNULL function
  • G. a scalar function
  • H. the TRY_CONVERT function
Show Suggested Answer Hide Answer
Suggested Answer: H 🗳️
A TRY_CONVERT function returns a value cast to the specified data type if the cast succeeds; otherwise, returns null.
References:
https://msdn.microsoft.com/en-us/library/hh230993.aspx

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
exam_taker5
Highly Voted 5 years, 11 months ago
I believe this should be TRY_PARSE, which is used specifically for date conversion. It includes an input parameter for culture type.
upvoted 27 times
...
M4x
Highly Voted 5 years, 9 months ago
TRY_PARSE accept a string_value AS data_type, since question do not specify the column type I think TRY_CONVERT is a better answer.
upvoted 6 times
truthee
5 years, 1 month ago
TRY_CONVERT does not have any 'culture format', since the 'en-US' was specified, it cannot be TRY_CONVERT. SELECT TRY_PARSE('Jabberwokkie' AS datetime2 USING 'en-US') AS Result; ---While this will return NULL as Result; SELECT TRY_CONVERT(datetime2, '12/31/2010', 'en-US') AS Result; ---this will return an error--- "Msg 8116, Level 16, State 1, Line 31 But, SELECT TRY_CONVERT(datetime2, '12/31/2010', 1) AS Result; ---will return a NULL. So the simple fact that you can't specify 'en-US' as the third parameter for a TRY_CONVERT eliminates it completely as an option. Argument data type varchar is invalid for argument 3 of convert function."
upvoted 2 times
truthee
5 years, 1 month ago
TRY_CONVERT does not have any 'culture format', since the 'en-US' was specified, it cannot be TRY_CONVERT. SELECT TRY_PARSE('Jabberwokkie' AS datetime2 USING 'en-US') AS Result; ---While this will return NULL as Result; SELECT TRY_CONVERT(datetime2, '12/31/2010', 'en-US') AS Result; ---this will return an error--- "Msg 8116, Level 16, State 1, Line 31 Argument data type varchar is invalid for argument 3 of convert function." But, SELECT TRY_CONVERT(datetime2, '12/31/2010', 1) AS Result; ---will return a NULL. So the simple fact that you can't specify 'en-US' as the third parameter for a TRY_CONVERT eliminates it completely as an option. EDIT: the last line of the first response was misplaced. this is the correct response.
upvoted 1 times
...
...
Billybob0604
4 years, 5 months ago
"You need to convert the data into a valid date time value using the en-US format culture code." How about that ?
upvoted 1 times
...
...
Ankita10feb
Most Recent 4 years, 5 months ago
select TRY_PARSE('2/1/2019' AS datetime USING 'en-US') select TRY_Convert( datetime,'2/1/2019',101) select TRY_PARSE('22/1/2019' AS datetime USING 'en-US') select TRY_Convert( datetime,'22/1/2019',101) 101 is style format for en-us in convert. and convert can be used to convert from any data type to date time. So try_convert is correct answer in this case.
upvoted 1 times
...
Vermonster
4 years, 5 months ago
Definitely TRY_PARSE due to requirement for 'en-US' format. Not sure why there is discussion
upvoted 2 times
...
Hoglet
4 years, 6 months ago
TRY_PARSE will only accept a String, and convert that to most data types. You can specify a culture (i.e. en-US) of the input string. TRY_CONVERT will take most data types and convert to most data types. It's possible to specify a format of the output string when converting from a date(time), but influenced by the current culture The requirement is to convert a string (It's not possible to have a datetime in an "invalid" format, so the source has to be a string), using a given culture, into a datetime. The only answer is TRY_PARSE.
upvoted 1 times
...
Andy7622
4 years, 7 months ago
TRY_PARSE uses the culture as argument. The answer is TRY_PARSE
upvoted 1 times
...
Oooo
4 years, 9 months ago
guys the answer is try_parse. The correct syntax for try_parse is TRY_PARSE(string as datatype [using culture]). Culture is an optional argument which helps to convert the value into culture format. Ex you want to display the date in french then you can pass the culture type as 'Fr-FR' for US English it should be 'en-US' Hope this clears. Happy learning :)
upvoted 1 times
Luzix
4 years, 7 months ago
SELECT TRY_PARSE(@field_to_convert AS DATE USING 'en-US');
upvoted 1 times
...
...
Aghie
4 years, 10 months ago
'using the en-US format culture code' this clearly for TRY_PARSE
upvoted 1 times
...
julie2020
4 years, 11 months ago
I would say: [H] the TRY_CONVERT function. What think guys? I have exam in 5 days if you can response before then that would be good?
upvoted 1 times
...
rustyG
5 years ago
Truthee, question did not specify that you must use ‘en-US’, it reference the used of code “using the en-US format culture code”. Either one would work, but more correct was TRY_CONVERT
upvoted 1 times
...
truthee
5 years, 1 month ago
TRY_CONVERT does not have any 'culture format', since the 'en-US' was specified, it cannot be TRY_CONVERT. SELECT TRY_PARSE('Jabberwokkie' AS datetime2 USING 'en-US') AS Result; ---While this will return NULL as Result; SELECT TRY_CONVERT(datetime2, '12/31/2010', 'en-US') AS Result; ---this will return an error--- "Msg 8116, Level 16, State 1, Line 31 Argument data type varchar is invalid for argument 3 of convert function." But, SELECT TRY_CONVERT(datetime2, '12/31/2010', 1) AS Result; ---will return a NULL. So the simple fact that you can't specify 'en-US' as the third parameter for a TRY_CONVERT eliminates it completely as an option. So the answer is TRY_PARSE
upvoted 2 times
...
matija1
5 years, 4 months ago
I think Try_CONVERT since it wants null if it fails, TRY_PARSE will return error on failure to convert
upvoted 3 times
...
gtc108
5 years, 5 months ago
Both TRY_CONVERT and TRY_PARSE will work with this scenario however, there is an overhead to using TRY_PARSE. Because of this, TRY_CONVERT is the best solution: https://docs.microsoft.com/en-us/sql/t-sql/functions/try-parse-transact-sql?view=sql-server-ver15,
upvoted 1 times
...
Robintang0924
5 years, 5 months ago
agreed with Exam_taker5 and Avramov, Try_Parse and Try_Convert both could take date string input and return null if error happens, however question clearly asked for 'culture code' which is specific to try_parse definition below. TRY_PARSE ( string_value AS data_type [ USING culture ] ) https://docs.microsoft.com/en-us/sql/t-sql/functions/try-parse-transact-sql?view=sql-server-ver15
upvoted 2 times
...
ivanbtod
5 years, 5 months ago
I think it should be try_parse due to the hint 'using the en-US format culture code'
upvoted 1 times
...
tubis
5 years, 7 months ago
"Try_Convert" does not throw an error when the conversion is not explicitly permitted. And base on the reference book, it recommends using "Try_Convert" rather than Try_Parse, even though the "Try_Convert" has lower performance
upvoted 2 times
...
mlourinho
5 years, 7 months ago
The requirement is "The conversion process must not throw an error". "Try_Convert" throws an error when we try to perform a conversion that is not explicitly permitted. On the other hand, "TRY_PARSE" function can only convert strings to numeric or date data types. It seems to me that the most probable answer is "TRY_PARSE".
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...