PrepAway - Latest Free Exam Questions & Answers

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?

PrepAway - Latest Free Exam Questions & Answers

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

9 Comments on “Which Transact-SQL query should you use?

  1. Janko Dones says:

    A & B return zero rows
    C & D return correct rows

    Answer D

    Running C & D in the same batch, the Execution plan clearly shows that C take 92% of the time and D only 8%




    0



    0
    1. wanjaledeepak@gmail.com says:

      Dont blame anyone ,without any proof .

      I have valid dumps and i know the quality of the dumps.

      I know you are Shreeroberts and putting fake comment here




      0



      0

Leave a Reply