Solved

How to number records individually when more than one record exists with the same datetime

Posted on 2014-10-28
5
120 Views
Last Modified: 2014-10-28
I have a table that is populated by a different company and can not have them insert the time differently.  The records come looking like image 1.  As you can see the highlighted records show 2 different records but with the same time and date.  
Image1.
I need to number the records for each date 1,2,3,4......  Like image2.  The order of the records for each date are not important, just how many there were and the amount.    
Image2Image3 will give you an idea of what we are trying to accomplish in the end.
Image3Thank you.
0
Comment
Question by:rcowen00
  • 3
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
Haris Djulic earned 500 total points
Comment Utility
try this:

SELECT 
   Location, depositdate,amount, id    
   ROW_NUMBER() OVER (PARTITION BY Location, depositdate ORDER By Location, depositdate) as depNumber
FROM SOURCE

Open in new window

0
 

Author Comment

by:rcowen00
Comment Utility
I tried in this stored procedure and am getting "incorrect syntax near )"

SELECT Locations.[Location Name] AS LocationName, Deposits.Date, Deposits.Amount,
      Deposits.Id, StoreType.StoreTypeName, id    
   ROW_NUMBER() OVER (PARTITION BY Location, depositdate ORDER By Location, depositdate) As depNum
FROM         Locations INNER JOIN
                      Deposits ON Locations.LocationNameOrig = Deposits.[Location Name] LEFT OUTER JOIN
                      StoreType ON Locations.StoreTypeID = StoreType.StoreTypeID
GROUP BY Locations.[Location Name], Deposits.Date, Deposits.Amount, Deposits.Id, StoreType.StoreTypeName
HAVING      (Deposits.Date BETWEEN @Begin AND @End) AND (Locations.[Location Name] = N'POS013')
0
 
LVL 15

Expert Comment

by:Haris Djulic
Comment Utility
Try this:

SELECT Locations.[Location Name] AS LocationName, Deposits.Date, Deposits.Amount, 
      Deposits.Id, StoreType.StoreTypeName, id    
   ROW_NUMBER() OVER (PARTITION BY Location, depositdate ORDER By Location, depositdate) As depNum 
FROM         Locations INNER JOIN
                      Deposits ON Locations.LocationNameOrig = Deposits.[Location Name] LEFT OUTER JOIN
                      StoreType ON Locations.StoreTypeID = StoreType.StoreTypeID
					  where       (Deposits.Date BETWEEN @Begin AND @End) AND (Locations.[Location Name] = N'POS013')
GROUP BY Locations.[Location Name], Deposits.Date, Deposits.Amount, Deposits.Id, StoreType.StoreTypeName

Open in new window

0
 

Author Comment

by:rcowen00
Comment Utility
I got it, I was missing a comma
0
 

Author Closing Comment

by:rcowen00
Comment Utility
This is the final

SELECT Locations.[Location Name], Deposits.Date, Deposits.Amount,
      Deposits.Id, StoreType.StoreTypeName,
   ROW_NUMBER() OVER(PARTITION BY Locations.[Location Name], Deposits.Date ORDER By [Locations].[Location Name], Deposits.Date) As depNum
FROM         Locations INNER JOIN
                      Deposits ON Locations.LocationNameOrig = Deposits.[Location Name] LEFT OUTER JOIN
                      StoreType ON Locations.StoreTypeID = StoreType.StoreTypeID
GROUP BY Locations.[Location Name], Deposits.Date, Deposits.Amount, Deposits.Id, StoreType.StoreTypeName
HAVING      (Deposits.Date BETWEEN @Begin AND @End) AND (Locations.[Location Name] = N'POS013')
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
how to fix this error 14 45
Why is "packages element is not declared"? 2 34
Row-Level Security 2 15
Sql query 34 16
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now