exam questions

Exam 70-761 All Questions

View all questions & answers for the 70-761 exam

Exam 70-761 topic 1 question 154 discussion

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

Note: This question is part of a series of questions that present the same scenario. Each question in the series contains a unique solution that might meet the stated goals. Some question sets might have more than one correct solution, while others might not have a correct solution.
After you answer a question in this section. You will NOT be able to return to it. As a result, these questions will not appear in the review screen.
You have a database that contains a single table named tblVehicleRegistration. The table is defined as follows:

You run the following query:

The query output window displays the following error message: "Conversion failed when converting the varchar value "˜AB012' to data type int."
You need to resolve the error.
Solution: You modify the Transact-SQL statement as follows:

Does the solution meet the goal?

  • A. Yes
  • B. No
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

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
Dieter
Highly Voted 5 years, 10 months ago
IMO is the correct answer B since it can occur taht the RegistrationNumber holds alphanumerical data (due to that it holds the data type varchar(5))
upvoted 22 times
avramov
5 years, 7 months ago
but in this paticular case they ask us to cast 20012 and this is just a number
upvoted 1 times
mlourinho
5 years, 7 months ago
IF OBJECT_ID('TEMPDB..#tblVehicleRegistration') IS NOT NULL DROP TABLE #tblVehicleRegistration GO CREATE TABLE #tblVehicleRegistration ( VehicleID INT PRIMARY KEY IDENTITY , RegistrationNumber VARCHAR(5) , RegistrationDate DATE , UserID INT ) GO INSERT INTO #tblVehicleRegistration(RegistrationNumber, RegistrationDate, UserID) VALUES ('XBP01', GETDATE(), 1) , ('ABC45', GETDATE(), 2) SELECT UserID FROM #tblVehicleRegistration WHERE CAST(RegistrationNumber AS INT) = 20012 AND RegistrationDate > '2016-01-01'
upvoted 7 times
...
HaykM
4 years, 6 months ago
sql server trying to cast RegistrationNumber to int because of int data type precedence is higher then char's
upvoted 1 times
...
...
...
safiullah
Highly Voted 5 years, 10 months ago
It will not work because CAST tries to do the same implicit conversion explicitly which was failing and it will fail again because there are 'letters' inside the RegistrationNumber column which can not be converted to an int type. So the correct answer is no.
upvoted 22 times
...
Billybob0604
Most Recent 4 years, 5 months ago
Correct. Answer = B. You just cannot convert character values. If ALL the registration numbers would have been 20012 though it would have worked.
upvoted 1 times
...
Andy7622
4 years, 6 months ago
Cast doesnt work here
upvoted 1 times
...
stm22
4 years, 11 months ago
"You need to resolve the error." Answer A) does resolve the error in this case. Maybe we'll find out on the exam!
upvoted 1 times
...
Backy
5 years ago
This cast works only if RegistrationNumber holds a string with integer value, it will fail if it has any non digits, so the correct answer is B -------------------------------------- DECLARE @RegistrationNumber1 varchar(5) ='20012' DECLARE @RegistrationNumber2 varchar(5) ='AB012' PRINT CAST(@RegistrationNumber1 AS int) PRINT CAST(@RegistrationNumber2 AS int) // Output 20012 Msg 245, Level 16, State 1, Line 4 Conversion failed when converting the varchar value 'AB012' to data type int.
upvoted 4 times
...
Anette
5 years ago
It seems strange because registration number is varchar type but in fact it works. Tested, Correct (A)
upvoted 1 times
Anette
5 years ago
But if registration number contains letter it fails to convert. So its NO
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 ...