|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, January 21, 2013 12:45 PM
Points: 20,
Visits: 135
|
|
I've attached a screenshot of a selection of records from a staging table I'm using in my SSIS package. I need to iterate through these records and capture every "target_acquired"/"target_lost" combination by Auid. The trick is I need to ignore any additional "target_acquired" values before the "target_lost" record is found. I've color-coded the attached screenshot to show how the records should be grouped (all rows in white are the "ignored" rows).
Any advice on how to approach this would be much appreciated.
|
|
|
|
|
Right there with Babe
      
Group: General Forum Members
Last Login: Yesterday @ 11:10 AM
Points: 740,
Visits: 785
|
|
MattieMich7 (12/19/2012) I've attached a screenshot of a selection of records from a staging table I'm using in my SSIS package. I need to iterate through these records and capture every "target_acquired"/"target_lost" combination by Auid. The trick is I need to ignore any additional "target_acquired" values before the "target_lost" record is found. I've color-coded the attached screenshot to show how the records should be grouped (all rows in white are the "ignored" rows). Just going from your data and assuming the id column is an identity column and that all aquired records have a lost record, couldn't you do something like:
SELECT MIN(Id) AS FirstAquiredId, MAX(Id) AS LastLostId, AuId FROM dbo.YourTable GROUP BY AuId ORDER BY AuId;
That would give you the Ids you're interested in. You could then unpivot this to get rows for each id. See if that gives you a start.
HTH, Rob
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, January 21, 2013 12:45 PM
Points: 20,
Visits: 135
|
|
I don't believe the above approach will work because there could be multiple Acquired/Lost combinations for a single Auid (sorry, should have explained that in my original post). For example, the result of the query when run against the records in the screenshot I provided is:
FirstAquireID=2 LastLostID=34 Auid=71127c4145a...
What I ended up doing (and still have more testing to do), is use a modified version of the what was explained in this article: http://www.sqlservercentral.com/articles/T-SQL/68467/
Using this method, I was able to flag and delete the unwanted rows from the staging table.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 5:15 PM
Points: 6,720,
Visits: 11,756
|
|
Which version of SQL Server are you using?
__________________________________________________________________________________________________ There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Believe you can and you're halfway there. --Theodore Roosevelt
Everything Should Be Made as Simple as Possible, But Not Simpler --Albert Einstein
The significant problems we face cannot be solved at the same level of thinking we were at when we created them. --Albert Einstein
1 apple is not exactly 1/8 of 8 apples. Because there are no absolutely identical apples. --Giordy
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Monday, January 21, 2013 12:45 PM
Points: 20,
Visits: 135
|
|
|
|
|