Solved

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

Posted on 2014-10-28
5
135 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
ID: 40409389
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
ID: 40409568
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
ID: 40409574
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
ID: 40409575
I got it, I was missing a comma
0
 

Author Closing Comment

by:rcowen00
ID: 40409612
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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A recent question popped up and the discussion heated up regarding updating a COMMENTS (TXT) field in a table using SSRS. http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/MS-SQL_Reporting/Q_27475269.html?cid=1572#a37227028 (htt…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

828 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