Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase ««12

Get last transaction from multiple groups of records Expand / Collapse
Author
Message
Posted Tuesday, August 06, 2013 1:26 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Monday, September 09, 2013 11:03 AM
Points: 21, Visits: 140
I've gotten a little further

Step 1 query gets me this:
c_iD1 c_rep c_Date
11111 23 2010-09-06
11111 25 2010-10-06

In step 2 I need to look at different data from the same table and find records where c_iD1 = c_iD AND
my "last_date" is < c_Date in order to return:

c_iD1 c_rep1 c_Date c_rep last_dt
11111 23 2010-09-06 25 2010-09-03
11111 25 2010-10-06 28 2010-10-02


I did not include the column "last_dt" in the create #mytable code simply to keep the first step simple, but basically, it is selected from #mytable in step 2 and compared to c_Date from ther first query.
Post #1481518
Posted Tuesday, August 06, 2013 1:29 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Yesterday @ 2:24 PM
Points: 11,990, Visits: 11,007
Lrobinson 93181 (8/6/2013)
I've gotten a little further

Step 1 query gets me this:
c_iD1 c_rep c_Date
11111 23 2010-09-06
11111 25 2010-10-06

In step 2 I need to look at different data from the same table and find records where c_iD1 = c_iD AND
my "last_date" is < c_Date in order to return:

c_iD1 c_rep1 c_Date c_rep last_dt
11111 23 2010-09-06 25 2010-09-03
11111 25 2010-10-06 28 2010-10-02


I did not include the column "last_dt" in the create #mytable code simply to keep the first step simple, but basically, it is selected from #mytable in step 2 and compared to c_Date from ther first query.


Well if you want my help you have to provide all of the info. Please post ddl with all the columns and the correct data that will match that output. I am willing to help but we just keep going around in circles.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1481521
« Prev Topic | Next Topic »

Add to briefcase ««12

Permissions Expand / Collapse