Efficient SQL Select Statement

I have the following data in the attached Excel file, and would like to return the below results. These are from a scanned equipment Database. I am looking for an efficient SQL Statement to produce this with the following arguments:
ScanType = 3 and ItemNumber is 11944 (What I am looking for is equipment scanned on a daily basis at a job (21 X..) but if it is scanned multiple times for 1 job in the same day, just need to return the latest time of that UPC code for that day...

Location                         UPC                          Date    
21 x Street                     103                            9/28/15
21 x Street                     105                            9/28/15
21 x Street                     106                            9/28/15
21 x Street                     108                            9/28/15
21 x Street                     103                            9/29/15
21 x Street                     5                                9/29/15
21 x Street                     106                            9/29/15
21 x Street                     108                            9/29/15

As you can see from the data attached  "103" is scanned 3 times in one day, I just need the latest timestamp from that day on that UPC Code for that job "21 x Street" or, item number "11944" which is the ID of that job.
Data that is in the excel file is this below:

ID      Location      UPC      DateTimeStamp      Employee      ScanType      ItemNumber
51      Baltimore Warehouse      103      09/28/15 15:16:31      9001      1      2
52      Baltimore Warehouse      104      09/28/15 15:16:31      9001      1      2
53      Baltimore Warehouse      105      09/28/15 15:16:31      9001      1      2
54      Baltimore Warehouse      106      09/28/15 15:16:31      9001      1      2
55      Baltimore Warehouse      107      09/28/15 15:16:31      9001      1      2
56      Pottstown Warehouse      108      09/28/15 15:16:51      9001      1      1
57      Pottstown Warehouse      109      09/28/15 15:16:51      9001      1      1
58      Pottstown Warehouse      107      09/28/15 15:16:51      9001      1      1
59      (14) Cargo Van              103      09/28/15 15:17:14      9001      2      5
60      (14) Cargo Van              104      09/28/15 15:17:14      9001      2      5
61      (14) Cargo Van             105      09/28/15 15:17:14      9001      2      5
62      (14) Cargo Van             107      09/28/15 15:17:14      9001      2      5
63      21 x Street                    103      09/28/15 15:17:36      9001      3      11944
64      21 x Street                    105      09/28/15 15:17:36      9001      3      11944
65      21 x Street                   106      09/28/15 15:17:36      9001      3      11944
66      21 x Street                   108      09/28/15 15:17:36      9001      3      11944
67      Sterling Warehouse      200      09/29/15 8:17:57         9001      1      5
68      Sterling Warehouse      210      09/29/15 8:17:57        9001      1      5
69      Sterling Warehouse      220      09/29/15 8:17:57        9001      1      5
70      Sterling Warehouse      230      09/29/15 8:17:57             9001       1      5
71      21 Church Street      103      09/29/15 9:06:28                 9001      3      11944
72      21 x Street      5      09/29/15 9:06:28                        9001      3      11944
73      21 x Street      106      09/29/15 9:06:29                              9001      3      11944
74      21 x Street      108      09/29/15 9:06:29                         9001      3      11944
75      21 x Street      103      09/29/15 9:06:52                        9001      3      11944
77      21 x Street      103      09/29/15 0:00:00                         9001      3      11944
Book1.xlsx
BKennedy2008Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Scott PletcherSenior DBACommented:
SELECT Location, UPC, DATEADD(DAY, DATEDIFF(DAY, 0, DateTimeStamp ), 0) AS Date
FROM (
    SELECT *, ROW_NUMBER() OVER(PARTITION BY ItemNumber, DATEADD(DAY, DATEDIFF(DAY, 0, DateTimeStamp ), 0) ORDER BY DateTimeStamp DESC) AS row_num
    FROM table_name
    WHERE
        ScanType = '3' and
        ItemNumber = '11944'
) AS derived
WHERE row_num = 1
--ORDER BY Location, UPC, Date
BKennedy2008Author Commented:
No- All that produces is:
21 X Street  108  9-28
21 X Street   103  9-29
Scott PletcherSenior DBACommented:
I left the UPC code out of the partitioning:
...
ROW_NUMBER() OVER(PARTITION BY ItemNumber, UPC, DATEADD(DAY, DATEDIFF(DAY, 0, DateTimeStamp ), 0)
...
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

BKennedy2008Author Commented:
That's pretty interesting how you came up with that, I would have thought you would have used an inner join with a Max(Datetimestamp) somehow.
Do you think this is an efficient query when I am running on thousands of records?
Scott PletcherSenior DBACommented:
ROW_NUMBER() is very efficient.  Yes, prior to it we'd have been forced to do an INNER JOIN on a MAX() with a GROUP BY, but R_N is now available, and it's much better for this type of thing.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BKennedy2008Author Commented:
Thanks for the lesson, Appreciate it!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.