You have a database that contains the tables as shown below:
You have a stored procedure named Procedure1. Procedure1 retrieves all order ids after a specific date. The
rows for Procedure1 are not sorted. Procedure1 has a single parameter named Parameter1. Parameter1 uses
the varchar type and is configured to pass the specific date to Procedure1. A database administrator discovers
that OrderDate is not being compared correctly to Parameter1 after the data type of the column is changed to
datetime. You need to update the SELECT statement to meet the following requirements:
The code must NOT use aliases.
The code must NOT use object delimiters.
The objects called in Procedure1 must be able to beresolved by all users.
OrderDate must be compared to Parameter1 after the data type of Parameter1 is changed to datetime.
Which SELECT statement should you use?
To answer, type the correct code in the answer area.
A.
Explanation:
SELECT Orders.OrderID
FROM Orders
WHERE Orders.OrderDate>CONVERT(datetime,@Parameter1)
I think is better to replace CONVERT() with CAST() because is ANSI compliant.
I agree with Joe, in addition CAST is standard.
Standard SQL:
SELECT Orders.OrderID
FROM Orders
WHERE Orders.OrderDate>CAST(@Parameter1 AS datetime)
;
Agree with Yommy
convert has an optional parameter style, and I suggest to use convert instead of cast. It helps to avoid confusion. For example, if you write cast(‘20130302’ as date), what would you get? March 2 or February 3?
Also, if you want specific format when casting to date to string, you bound to use convert
convert has an optional parameter style, and I suggest to use convert instead of cast. It helps to avoid confusion. For example, if you write cast(‘20130302’ as date), what would you get? March 2 or February 3?
Also, if you want specific format when casting to date to string, you bound to use convert
Here is an excellent Weblog You may Come across Intriguing that we encourage you to visit.
Here is a great Blog You may Locate Intriguing that we Encourage You