Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
someoneintheworld
Starting Member
1 Post |
Posted - 2008-03-13 : 14:14:05
|
| Hi,I have a question about historical table. I have a table in Sql Server that keeps the history of my clients for the last 3 months. This table has a PK : client_code and rep_date_id. I want to do a query that returns me a client and to extract the date when i inregistreted for the first time.I think about a cursor, but i don't know how to use it.My table looks like this structure:- client_code-activity_code-country_code-district_code-...-rep_date_id_nAnd I want to return --activity_code-country_code-district_code-...-start_date-current_dateThanks |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2008-03-13 : 16:35:09
|
I'm not sure I fully understand your data, but maybe this is what you are looking for? SELECT *FROM historyINNER JOIN ( SELECT client_code, MIN(rep_date_id) FROM history GROUP BY client_code ) MinHistory ON History.client_code = MinHistory.client_code AND History.rep_date_id = MinHistory.rep_date_id |
 |
|
|
|
|
|