Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam 70-761 All Questions

View all questions & answers for the 70-761 exam

Exam 70-761 topic 1 question 128 discussion

Actual exam question from Microsoft's 70-761
Question #: 128
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: B 🗳️
https://docs.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql?view=sql-server-2017

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
Dieter
Highly Voted 5 years, 2 months ago
IMO the correct answer is A since the data type of the RegistrationNumber = varchar(5) and the predicate value is explicitely casted as well to varchar(5), thus no errors should occur
upvoted 29 times
AshleyLiang
5 years, 2 months ago
Agree.
upvoted 5 times
...
okh
5 years, 1 month ago
Agree A is correct. Tested DROP TABLE IF EXISTS tblVehicleRegistration CREATE TABLE tblVehicleRegistration ( VehicleID int, RegistrationNumber varchar(5), RegistrationDate date, UserId int ) INSERT INTO tblVehicleRegistration VALUES (1,'20012', GETDATE(),1) SELECT UserId FROM tblVehicleRegistration WHERE RegistrationNumber = CAST(20012 AS varchar(5)) AND RegistrationDate > '2016-01-01'
upvoted 11 times
...
...
Sis_
Most Recent 3 years, 9 months ago
I think we should use CAST to INT, hence the error message is: "Conversion failed when converting the varchar value "˜AB012' to data type int."
upvoted 1 times
...
Vermonster
3 years, 10 months ago
correct
upvoted 1 times
...
Andy7622
3 years, 10 months ago
Precedence of INT is higher than char so Explicit conversion is need . I think the answer is A
upvoted 1 times
...
Braindripper
4 years, 1 month ago
Answer is A - and taking your examples bellow modifying it to be more...correct example: DROP TABLE IF EXISTS tblVehicleRegistration CREATE TABLE tblVehicleRegistration ( VehicleID int, RegistrationNumber varchar(5), RegistrationDate date, UserId int ) INSERT INTO tblVehicleRegistration VALUES (1,'20012', GETDATE(),1), (2,'AB012', GETDATE(),2) -- text record added as well SELECT UserId FROM tblVehicleRegistration WHERE RegistrationNumber = CAST(20012 AS varchar(5)) AND RegistrationDate > '2016-01-01'
upvoted 4 times
...
chaoxes
4 years, 3 months ago
Answer is A. Yes. Tested it. create table tblvehicleregistration (vehicleid int identity(1,1) ,registrationnumber varchar(5) ,registrationdate date ,userid int ) select * from tblvehicleregistration insert into tblvehicleregistration values ('20012', getdate(), '1') select userid from tblvehicleregistration where registrationnumber = cast(20012 as varchar(5)) and registrationdate > '2016-01-01'
upvoted 2 times
...
mamarach
4 years, 4 months ago
SELECT CONVERT(int, 25.65); SELECT CAST('2017-08-25' AS datetime);
upvoted 1 times
...
gtc108
4 years, 9 months ago
Place literal quotes '12345' and it will work.
upvoted 4 times
...
New_user
4 years, 10 months ago
B is correct. Despite solution fixed reg. number's problem, the date still must be converted
upvoted 1 times
MarcusJB
4 years, 8 months ago
No, because '2016-01-01' will be implicitly and correctly converted to the datatype DATE. Solution tested on SQL Server 2016. Answer A is correct.
upvoted 6 times
...
...
fabzo
4 years, 11 months ago
B is correct as the from DB needs to come after the cast function
upvoted 2 times
supermario
4 years, 8 months ago
no. There is a FROM clause in first line. A is correct
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 ...