You work as a SQL Server 2012 database developer at ABC.com. ABC.com has a database
named SalesDB with tables named Customer and Orders. The Customer and Orders tables were
created using the following Transact-SQL code:
CREATE TABLE SalesDB.Customers
(
CustomerID int NOT NULL PRIMARY KEY,
CustomerName nvarchar (250) NOT NULL,
Address1 nvarchar (100) NOT NULL,
Address2 nvarchar (100) NULL,
City nvarchar (50) NOT NULL,
State nvarchar (50) NOT NULL,
Zip varchar (5) NOT NULL,
Phone varchar (10) NOT NULL
)
GO
CREATE TABLE SalesDB.Orders
(
OrderID int NOT NULL PRIMARY KEY,
CustomerID int NOT NULL,
OrderDate datetime NOT NULL,
ShipDate datetime NOT NULL,
CustomerID int NOT NULL,
SalesRepID int NOT NULL
)
GO
You are developing a stored procedure named OrdersByDate that returns the OrderID,
CustomerID, CustomerName and OrderDate. The stored procedure will take a parameter named
@date that uses the int datatype. The @date parameter will be used to filter the result set based
on the OrderDate column in the Orders table.
How would you create the stored procedure?

A.
CREATE PROCEDURE OrdersByDate
@date int
AS
SELECT OrderID, CustomerID, CustormerName, OrderDate
FROM Orders INNER JOIN Customers ON Orders.CustomerId = Customers.CustomerId
WHERE OrderDate = CONVERT(datetime,@date)
B.
CREATE PROCEDURE OrdersByDate
@date int
AS
SELECT OrderID, CustomerID, CustormerName, OrderDate
FROM Orders INNER JOIN Customers ON Orders.CustomerId = Customers.CustomerId
WHERE OrderDate =@date
C.
CREATE PROCEDURE OrdersByDate
@date int
AS
SELECT OrderID, CustomerID, CustormerName, OrderDate
FROM Orders INNER JOIN Customers ON Orders.CustomerId = Customers.CustomerId
WHERE OrderDate = CAST(@date AS datetime)
D.
CREATE PROCEDURE OrdersByDate
@date int
AS
SELECT OrderID, CustomerID, CustormerName, OrderDate
FROM Orders INNER JOIN Customers ON Orders.CustomerId = Customers.CustomerId
WHERE OrderDate = PARSE(@date AS datetime)
Explanation:
why not A ?!
0
0
A, B, and C work if there is no time component in the datetime value. I always thought CONVERT was preferred over CAST.
0
0
-CONVERT is “nonstandard” (according to the 70-461 training kit book) which is probably why the answer is C
0
0
B IS NOT AN OPTION AS IT COMPARES INT WITH DATETIME WHICH IS DIFFERENT FORMAT.
A,C BOTH SHOULD WORK
0
0
There is syntax error
Msg 209, Level 16, State 1, Procedure OrdersByDate, Line 4
Ambiguous column name ‘CustomerID’.
Once this is resolved [Table].CustomerID
Then either of A,B,C will work
0
0
I think this question is wrong because both a,c are correct i tried both of them give the same results
0
0
BTW, part of that new 200Q 70-461 dumps are available here:
https://drive.google.com/open?id=0B-ob6L_QjGLpfnJldlZxTklTaHM0akpJUzhja2pETHJOS0owMzd4eVk1UTVNQUpvdlVxVWM
Best Regards!
0
0