Which Transact-SQL query should you use?

Your database contains a table named SalesOrders. The table includes a DATETIME
column named OrderTime that stores the date and time each order is placed. There is a
non-clustered index on the OrderTime column. The business team wants a report that
displays the total number of orders placed on the current day.
You need to write a query that will return the correct results in the most efficient manner.
Which Transact-SQL query should you use?

Your database contains a table named SalesOrders. The table includes a DATETIME
column named OrderTime that stores the date and time each order is placed. There is a
non-clustered index on the OrderTime column. The business team wants a report that
displays the total number of orders placed on the current day.
You need to write a query that will return the correct results in the most efficient manner.
Which Transact-SQL query should you use?

A.
SELECT COUNT(*) FROM SalesOrders
WHERE OrderTime = CONVERT(DATE, GETDATE())

B.
SELECT COUNT(*) FROM SalesOrders
WHERE OrderTime = GETDATE()

C.
SELECT COUNT(*) FROM SalesOrders
WHERE CONVERT(VARCHAR, OrderTime, 112) = CONVERT(VARCHAR, GETDATE(I,
112))

D.
SELECT COUNT(*) FROM SalesOrders
WHERE OrderTime >= CONVERT(DATE, GETDATE())
AND OrderTime < DATEADD(DAY, CONVERT(DATE, GETDATE()))



Leave a Reply 3

Your email address will not be published. Required fields are marked *


id909

id909

The answer is C. with a little correction:

SELECT COUNT(*) FROM SalesOrders
WHERE CONVERT(VARCHAR, OrderTime, 112) = CONVERT(VARCHAR, GETDATE(), 112)

id909

id909

Actually and D should be also corect but should be changed to:

Select …… and DATEADD(DAY, 1, CONVERT(DATE, GETDATE()))

JosefTheGreat

JosefTheGreat

“most efficient manner!” -> D