Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2014-10-28
5
Medium Priority
?
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 15

Accepted Solution

by:
Haris Djulic earned 2000 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 Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

719 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