max(date) not working

I have a query and I am trying  to get only records with a max date by serial number
and it is not working - in the results file attached are you will notice serialnumber 8004608 and 8004606 are duplicated with different dates - I cant get it working - I need the one record with the max(Date)
SELECT isa.tooltype             AS 'tooltype', 
       sd.subsn                 AS 'altserialnumber', 
       isa.serialnumber         AS 'serialnumber', 
       Max(isa.uploaddate)      AS 'fuploadtime', 
       '1901-01-01 00:00:00 AM' AS 'huploadtime', 
       isa.locationid           AS 'defaultlocationindex', 
       isa.quantity             AS 'qty', 
       ''                       AS 'JobType' 
FROM   inventory_serializedassets AS isa 
       LEFT JOIN subdata AS sd 
              ON isa.serialnumber = sd.inventorysn 
WHERE  --locationid = 0 
       tooltype = 'SU'
GROUP  BY isa.SerialNumber,isa.uploaddate, isa.ToolType,sd.SubSN,isa.LocationID,isa.Quantity 

Open in new window

results.csv
LVL 6
r3nderAsked:
Who is Participating?
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.

r3nderAuthor Commented:
tried this but it didn't insert
INSERT INTO temp_mytools 
            (tooltype, 
             serialnumber, 
             altserialnumber, 
             fuploadtime, 
             huploadtime, 
             defaultlocationindex, 
             qty, 
             jobtype) 

SELECT tooltype             AS 'tooltype', 
       subsn                 AS 'altserialnumber', 
       serialnumber         AS 'serialnumber', 
       uploaddate      AS 'fuploadtime', 
       uploaddate    AS 'huploadtime', --'1901-01-01 00:00:00 AM'
       locationid           AS 'defaultlocationindex', 
       quantity             AS 'qty', 
       ''                       AS 'JobType' 
from
(
  select isa.tooltype, sd.subsn,isa.serialnumber,isa.uploaddate,'1901-01-01 00:00:00 AM' as 'huploadtime',isa.locationid,isa.quantity,
    row_number() over(partition by isa.serialnumber 
                        order by isa.uploaddate desc) seq
  from Inventory_SerializedAssets isa
  Left JOIN SubData sd on isa.SerialNumber = sd.InventorySN
  where ToolType='SU'
) d
where seq = 1;

Open in new window

0
YZlatCommented:
it might be the same serial number but if you tak those duplicate records, please not if the rest of the fields aare the same or different. I suspect the other fields might differ, so overall the record is unique

try something like that:

SELECT isa.tooltype             AS 'tooltype', 
       sd.subsn                 AS 'altserialnumber', 
       isa.serialnumber         AS 'serialnumber', 
       a.maxuploaddate          AS 'fuploadtime', 
       '1901-01-01 00:00:00 AM' AS 'huploadtime', 
       isa.locationid           AS 'defaultlocationindex', 
       isa.quantity             AS 'qty'
FROM   inventory_serializedassets AS isa 
       LEFT JOIN subdata AS sd 
              ON isa.serialnumber = sd.inventorysn 
INNER JOIN (SELECT serialnumber, MAX(uploaddate) as maxuploaddate FROM inventory_serializedassets GROUP BY serialnumber) as a
ON isa.serialnumber=a.serialnumber and isa.uploaddate=a.maxuploaddate 

Open in new window

0

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
r3nderAuthor Commented:
Thanks YZlat
0
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 2008

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.