--I have a table named - FacilityBillingCREATE TABLE FacilityBilling( GLOBAL_FACILITY_ID INT, BILLING_COMP_NAME VARCHAR(50), BILLING_START_DT DATETIME, BILLING_END_DT DATETIME)INSERT INTO FacilityBillingSELECT '10','EMBCC','2007-09-01 00:00:00.000','2099-12-31 00:00:00.000'UNION ALLSELECT '100','EPBS','2003-12-01 00:00:00.000','2009-03-19 00:00:00.000'UNION ALLSELECT '10017','EMBCC','2011-07-18 00:00:00.000','2099-12-31 00:00:00.000'UNION ALLSELECT '10190','EMBCC','2003-12-01 00:00:00.000','2004-12-01 00:00:00.000'UNION ALLSELECT '102','EPBS','2003-12-01 00:00:00.000','2007-06-23 00:00:00.000'UNION ALLSELECT '102','EPBS','2003-12-01 00:00:00.000','2007-06-23 00:00:00.000'UNION ALLSELECT '103','EPBS','2010-09-01 00:00:00.000','2099-12-31 00:00:00.000'UNION ALLSELECT '11198','EPBS','1900-01-01 00:00:00.000','2099-12-31 00:00:00.000'UNION ALLSELECT '11198','EPBS','2008-04-04 00:00:00.000','2008-07-31 00:00:00.000'UNION ALLSELECT '11989','EMBCC','1994-01-01 00:00:00.000','2099-12-31 00:00:00.000'UNION ALLSELECT '11989','EMBCC','2009-04-08 00:00:00.000','2099-12-31 00:00:00.000'UNION ALLSELECT '1212','EMBCC','2004-11-15 00:00:00.000','2007-12-31 00:00:00.000'UNION ALLSELECT '12199','EMBCC','2009-12-01 00:00:00.000','2010-10-30 00:00:00.000'UNION ALLSELECT '12253','LOYA','2009-06-06 00:00:00.000','2009-12-31 00:00:00.000'UNION ALLSELECT '12253','EMBCC','2010-01-01 00:00:00.000','2099-12-31 00:00:00.000'UNION ALLSELECT '9156','EMBCC','1994-01-01 00:00:00.000','2099-12-31 00:00:00.000'UNION ALLSELECT '9156','EMBCC','2009-02-01 00:00:00.000','2099-12-31 00:00:00.000'UNION ALLSELECT '9161','EMBCC','1900-01-01 00:00:00.000','2099-12-31 00:00:00.000'UNION ALLSELECT '9161','EPBS','2007-10-01 00:00:00.000','2008-12-04 00:00:00.000'
In the above table I have to find out incorrect record.For GLOBAL_FACILITY_ID there should be Billing company in sequenceif for one GLOBAL_FACILITY_ID there are multiple Billing Company thenStart Date should be greater than End date of previous company.Means dates should not be overlap.In the above case 11198, 11989, 9156, 9161 are incorrect.Can I write a query to get those incorrect GLOBAL_FACILITY_IDVaibhav TIf I cant go back, I want to go fast...