May 11, 2012 at 12:34 pm
I have this in one table (columns are Patient#, Name, EntryDate)
123456789, Jane Doe, 4/12/12
123456789, Jane Doe, 4/15/12
555666888, Alice Doe, 3/13/12
555666888, AliceDoe, 3/20/12
What t-sql can I use to pull the most recent entry date for each Patient#? This is what it should look like...
123456789, Jane Doe, 4/15/12
555666888, AliceDoe, 3/20/12
May 11, 2012 at 12:41 pm
sqluser_8119 (5/11/2012)
I have this in one table (columns are Patient#, Name, EntryDate)123456789, Jane Doe, 4/12/12
123456789, Jane Doe, 4/15/12
555666888, Alice Doe, 3/13/12
555666888, AliceDoe, 3/20/12
What t-sql can I use to pull the most recent entry date for each Patient#? This is what it should look like...
123456789, Jane Doe, 4/15/12
555666888, AliceDoe, 3/20/12
select
Patient#,
Name,
MAX(EntryDate)
from
dbo.OneTable -- Have no idea what your table name really is
group by
Patient#,
Name
order by
Patient#;
May 11, 2012 at 12:42 pm
This pretty simple but I am rather swamped at the moment. If you post ddl and insert statements I can knock this out in a couple minutes. I just don't have time to create your test data.
_______________________________________________________________
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/
May 11, 2012 at 12:44 pm
Sean Lange (5/11/2012)
This pretty simple but I am rather swamped at the moment. If you post ddl and insert statements I can knock this out in a couple minutes. I just don't have time to create your test data.
Just faster to give an answer. Let the OP figure out if it works or not.
May 11, 2012 at 12:48 pm
Lynn Pettis (5/11/2012)
Sean Lange (5/11/2012)
This pretty simple but I am rather swamped at the moment. If you post ddl and insert statements I can knock this out in a couple minutes. I just don't have time to create your test data.Just faster to give an answer. Let the OP figure out if it works or not.
Probably true.
_______________________________________________________________
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/
May 11, 2012 at 12:53 pm
Sweet it works! Thanks, Lynn 🙂
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply