hello experts, need your help
below i have 3 bans .. who has workflows created and ordered by CreateTimestamp . i need to count the number of workflows from top to point where there is either a success or failure workflow that occurs at the latest .
1.ban 137108351 has success workflow and prior to that workflow it has 2 workflows (exclude success and failure)
2.ban 104917284 has success workflow as latest (it still has failure but not considered because it is occurred earlier to success ) and prior to that workflow it has 2 workflows (exclude success and failure)
3.ban 107500674 has failure workflow and prior to that workflow it has 0 workflows (exclude success and failure)below provided code for sample data as well
GO /****** Object: Table [Temp].[deleteit] Script Date: 7/31/2015 3:04:55 PM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [Temp].[deleteit]( [ban] [nvarchar](256) NULL, [WORKFLOW_NM] [nvarchar](250) NULL, [WorkFlow_Create_TM] [datetime] NULL ) ON [PRIMARY] GO INSERT [Temp].[deleteit] ([ban], [WORKFLOW_NM], [WorkFlow_Create_TM]) VALUES (N'137108351', N'SS_UVERSE_MY_WIFI_PASSWORD', CAST(0x0000A4900068D2C4 AS DateTime)) GO INSERT [Temp].[deleteit] ([ban], [WORKFLOW_NM], [WorkFlow_Create_TM]) VALUES (N'137108351', N'SS_UVERSE_SMS_RESTORE', CAST(0x0000A4900068E908 AS DateTime)) GO INSERT [Temp].[deleteit] ([ban], [WORKFLOW_NM], [WorkFlow_Create_TM]) VALUES (N'137108351', N'SS_UVERSE_SUB_SUCCESS', CAST(0x0000A49000696D74 AS DateTime)) GO INSERT [Temp].[deleteit] ([ban], [WORKFLOW_NM], [WorkFlow_Create_TM]) VALUES (N'137108351', N'SS_UVERSE_TV_NO_SIGNAL', CAST(0x0000A4900069A5B4 AS DateTime)) GO INSERT [Temp].[deleteit] ([ban], [WORKFLOW_NM], [WorkFlow_Create_TM]) VALUES (N'104917284', N'SS_UVERSE_VIDEO_TV_TV_ON_DEMAND', CAST(0x0000A499017CD624 AS DateTime)) GO INSERT [Temp].[deleteit] ([ban], [WORKFLOW_NM], [WorkFlow_Create_TM]) VALUES (N'104917284', N'SS_UVERSE_SUB_FAILURE', CAST(0x0000A499017D9780 AS DateTime)) GO INSERT [Temp].[deleteit] ([ban], [WORKFLOW_NM], [WorkFlow_Create_TM]) VALUES (N'104917284', N'SS_UVERSE_TV_REMOTECONTROL_TROUBLESHOOT', CAST(0x0000A499017DBBD4 AS DateTime)) GO INSERT [Temp].[deleteit] ([ban], [WORKFLOW_NM], [WorkFlow_Create_TM]) VALUES (N'104917284', N'SS_UVERSE_SUB_SUCCESS', CAST(0x0000A499017DFD74 AS DateTime)) GO INSERT [Temp].[deleteit] ([ban], [WORKFLOW_NM], [WorkFlow_Create_TM]) VALUES (N'104917284', N'SS_UVERSE_VIDEO_INTERNET_TROUBLESHOOT', CAST(0x0000A499017E36E0 AS DateTime)) GO INSERT [Temp].[deleteit] ([ban], [WORKFLOW_NM], [WorkFlow_Create_TM]) VALUES (N'104917284', N'SS_UVERSE_MY_WIFI_PASSWORD', CAST(0x0000A499017E4E50 AS DateTime)) GO INSERT [Temp].[deleteit] ([ban], [WORKFLOW_NM], [WorkFlow_Create_TM]) VALUES (N'104917284', N'SS_UVERSE_SMS_RESTORE', CAST(0x0000A499017E6494 AS DateTime)) GO INSERT [Temp].[deleteit] ([ban], [WORKFLOW_NM], [WorkFlow_Create_TM]) VALUES (N'104917284', N'SS_UVERSE_INSTALL_WIRELESS_RECEIVER', CAST(0x0000A499017E8A14 AS DateTime)) GO INSERT [Temp].[deleteit] ([ban], [WORKFLOW_NM], [WorkFlow_Create_TM]) VALUES (N'107500674', N'SS_UVERSE_TV_DVR_PAUSE_LIVE_TV_V2', CAST(0x0000A49A01824E88 AS DateTime)) GO INSERT [Temp].[deleteit] ([ban], [WORKFLOW_NM], [WorkFlow_Create_TM]) VALUES (N'107500674', N'SS_UVERSE_SUB_FAILURE', CAST(0x0000A49A01824E88 AS DateTime)) GO