Friday, 15 May 2015

sql - Select most recent InstanceID base on max end date -


I am trying to drag member instances from the table based on the maximum date range. If this is the tap, then I want to draw it because it is still going on. I am using SQL Server

Choose from


Being a member of the group

MAX (ISNULL (date_end, '20 99-12-31 '))

This query does not work for me. I have tried different people and got it back in different instances, but not only with the maximum date.

How my table looks like below.

Member ID & nbsp; & Nbsp; & Nbsp; Member Instident ID & nbsp; & Nbsp; & Nbsp; Date start & nbsp; & Nbsp; & Nbsp; Date &&
& nbsp; & Nbsp; & Nbsp; & Nbsp; 2 & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; ABC 12 & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; 2013-01-01 & nbsp; & Nbsp; 2013-12-31
> & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; 4 & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; Abc21 & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; 2010-01-01 & nbsp; & Nbsp; 2013-12-31
> & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; 2 & nbsp; & Nbsp; & Nbsp; & Nbsp; And nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; Abc10 & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; 2015-01-01 & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; Faucet
& nbsp; & Nbsp; & Nbsp; & Nbsp; 4 & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; Abc19 & nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; & Nbsp; 2014-01-01 & nbsp; 2014-10-31

I hope my results will look like this

Members Intercitid
abc10
abc19

I am trying to understand how to do this but I have no luck. Any help would be much appreciated. Thank you

I think you need something like the following:

  Select Member ID, MemberInstanceID from Table T (--Daynd is not empty ... DateInd is empty or (- ... or choose the latest dateindex for this member ... Dateindia = (Select the maximum of the table) TMBIDID) - ... and check that this member does not have a blank entry for the date dated and does not exist (rhythm Select 1 from where the member ID = t.MemberID and date-end are empty))  

The problem with this approach will be that if there are multiple rows for each member, that is the same Multiple rows with member ID, or several rows along the same date for the same member ID.


No comments:

Post a Comment