• 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 Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/