Solved

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

Posted on 2014-10-28
5
127 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Interview questions for support of a legacy ASP.NET site 4 38
Run time Error 4 34
Managing Columnstore Indexes 2 15
Gridview alignment 1 9
Written by Valentino Vranken. Introduction: The first step of creating a SQL Server Reporting Services (SSRS) report involves setting up a connection to the data source and programming a dataset to retrieve data from that data source.  The data…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

910 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

24 Experts available now in Live!

Get 1:1 Help Now