Which Transact-SQL query should you use?

Your database contains a table named Purchases. The table includes a DATETIME column named
PurchaseTime that stores the date and time each purchase is made. There is a non-clustered index
on the PurchaseTime column. The business team wants a report that displays the total number of

purchases made 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 Purchases. The table includes a DATETIME column named
PurchaseTime that stores the date and time each purchase is made. There is a non-clustered index
on the PurchaseTime column. The business team wants a report that displays the total number of

purchases made 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 Purchases
WHERE PurchaseTime = CONVERT(DATE, GETDATE())

B.
SELECT COUNT(*)
FROM Purchases
WHERE PurchaseTime = GETDATE()

C.
SELECT COUNT(*)
FROM Purchases
WHERE CONVERT(VARCHAR, PurchaseTime, 112) = CONVERT(VARCHAR, GETDATE(), 112)

D.
SELECT COUNT(*)
FROM Purchases
WHERE PurchaseTime >= CONVERT(DATE, GETDATE())
AND PurchaseTime < DATEADD(DAY, 1, CONVERT(DATE, GETDATE()))

Explanation:
http://technet.microsoft.com/en-us/library/ms181034.aspx



Leave a Reply 2

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


Dan

Dan

70-461 question, not 70-462

Kevin Burgess

Kevin Burgess

Regardless…..would the WHERE not be

WHERE PurchaseTime > (GETDATE() – 1)

?