I have a table withe different columns as shown below
Ref Number Service Numbers Service type code OpenDate CurrentAppointDt PreviousAppointDt Time_Stamp Lettert_created
78892 485992 78892TA 02/16/12 04/17/12 03/21/12 2/17/12 9:00 AM FALSE
78892 485992 78892TA 02/16/12 04/17/12 03/21/12 3/19/12 9:29 AM FALSE
78892 485992 78892TA 02/16/12 04/17/12 03/21/12 3/19/12 9:30 AM TRUE
78892 485992 78892TA 02/16/12 04/17/12 03/21/12 3/8/12 11:32 AM FALSE
78892 485992 78892TA 02/16/12 04/17/12 03/21/12 3/20/12 9:59 AM FALSE
94329 140055 94329 03/21/07 04/20/07 04/02/07 2/1/12 9:41 AM FALSE
94329 140055 94329 03/21/07 04/20/07 04/02/07 3/21/07 10:00 AM FALSE
94329 140055 94329 03/21/07 04/20/07 04/02/07 3/21/07 10:09 AM FALSE
94329 140055 94329 03/21/07 04/20/07 04/02/07 3/22/07 11:21 AM FALSE
94329 140055 94329 03/21/07 04/20/07 04/02/07 3/27/07 9:01 AM FALSE
94329 140055 94329 03/21/07 04/20/07 04/02/07 3/27/07 12:19 PM FALSE
94329 140055 94329 03/21/07 04/20/07 04/02/07 12/2/11 12:55 PM FALSE
107126 478952 107126TA 02/06/12 03/28/12 02/28/12 3/16/12 4:52 PM FALSE
107126 478952 107126TA 02/06/12 03/28/12 02/28/12 3/16/12 5:33 PM TRUE
107126 478952 107126TA 02/06/12 03/28/12 02/28/12 3/16/12 11:58 AM FALSE
107126 478952 107126TA 02/06/12 03/28/12 02/28/12 3/14/12 2:09 PM FALSE
107126 478952 107126TA 02/06/12 03/28/12 02/28/12 2/24/12 2:00 PM FALSE
107126 478952 107126TA 02/06/12 03/28/12 02/28/12 2/24/12 12:15 PM FALSE
107126 478952 107126TA 02/06/12 03/28/12 02/28/12 2/24/12 12:15 PM FALSE
If I take the distinct values for the above Ref Number I get as follows
78892
94329
107126
The time_stamp is always between CurrentAppointDT and PreviousAppointDt.
For these RefNumbers I need to see if the ‘Lettercreated’ is False/true.
I need the output as follows:
Ref Number Service Numbers Service type code OpenDate CurrentAppointDt PreviousAppointDt Lettert_created
78892 485992 78892TA 02/16/12 04/17/12 03/21/12 TRUE
94329 140055 94329 03/21/07 04/20/07 04/02/07 FALSE
107126 478952 107126TA 02/06/12 03/28/12 02/28/12 TRUE
Please help me if i can get a T-sql script in 1 select statement. It is a great help if any one can give me a solution.
Thank you.
It looks like you’re just looking for the case where the reference number has any record set to “True”, otherwise list it as “False”. If this is the case, try this: