Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Nested If statement in a query

Status
Not open for further replies.

SACRob

Technical User
Apr 11, 2008
34
US
I am trying to do some line by line time calculations in a select statement using nested Ifs and i think my syntax is just a bit off. It is failing at the from statement in the last section of the code. please any help would be greatly appreciated.

Code:
CREATE PROCEDURE dbo.svcslr 
	-- Add the parameters for the stored procedure here
	(@callnbr char(11),
	 @startdate datetime,
	 @starttime datetime,
	 @enddate datetime,
	 @holdtime int output,
	 @worktime datetime output,
	 @flag int output,
	 @workingdate datetime,
	 @tempstat char(3)
	 )
	
as
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	set @workingdate=@startdate+@starttime
	set @tempstat='10E'
	set @worktime='0'
	SELECT [CALLNBR]
      ,[SRVRECTYPE]
      ,[LNITMSEQ]
      ,[FRMSTAT]
      ,[TOSTAT]
      ,[TECHID]
      ,[DSCRIPTN]
      ,[USERID]
      ,[CREATDDT]
      ,[CREATETIME]
      ,[DEX_ROW_ID]

 
	  if (@tempstat='04S' or FRMSTAT='04S')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='10E' or FRMSTAT='10E')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='20N' or FRMSTAT='20N')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='50D' or FRMSTAT='50D')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='60A' or FRMSTAT='60A')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='65A' or FRMSTAT='65A')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='00C' or FRMSTAT='00C')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='30B' or FRMSTAT='30B')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='40M' or FRMSTAT='40M')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='45I' or FRMSTAT='45I')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='50O' or FRMSTAT='50O')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='70C' or FRMSTAT='70C')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='72P' or FRMSTAT='72P')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='74I' or FRMSTAT='74I')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='74O' or FRMSTAT='74O')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='74S' or FRMSTAT='74S')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='75R' or FRMSTAT='75R')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='78M' or FRMSTAT='78M')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='79U' or FRMSTAT='79U')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='80R' or FRMSTAT='80R')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='90I' or FRMSTAT='90I')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
 
my code did not completly display.
Code:
CREATE PROCEDURE dbo.svcslr 
	-- Add the parameters for the stored procedure here
	(@callnbr char(11),
	 @startdate datetime,
	 @starttime datetime,
	 @enddate datetime,
	 @holdtime int output,
	 @worktime datetime output,
	 @flag int output,
	 @workingdate datetime,
	 @tempstat char(3)
	 )
	
as
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	set @workingdate=@startdate+@starttime
	set @tempstat='10E'
	set @worktime='0'
	SELECT [CALLNBR]
      ,[SRVRECTYPE]
      ,[LNITMSEQ]
      ,[FRMSTAT]
      ,[TOSTAT]
      ,[TECHID]
      ,[DSCRIPTN]
      ,[USERID]
      ,[CREATDDT]
      ,[CREATETIME]
      ,[DEX_ROW_ID]

 
	  if (@tempstat='04S' or FRMSTAT='04S')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='10E' or FRMSTAT='10E')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='20N' or FRMSTAT='20N')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='50D' or FRMSTAT='50D')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='60A' or FRMSTAT='60A')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='65A' or FRMSTAT='65A')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='00C' or FRMSTAT='00C')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='30B' or FRMSTAT='30B')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='40M' or FRMSTAT='40M')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='45I' or FRMSTAT='45I')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='50O' or FRMSTAT='50O')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='70C' or FRMSTAT='70C')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='72P' or FRMSTAT='72P')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='74I' or FRMSTAT='74I')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='74O' or FRMSTAT='74O')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='74S' or FRMSTAT='74S')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='75R' or FRMSTAT='75R')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='78M' or FRMSTAT='78M')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='79U' or FRMSTAT='79U')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='80R' or FRMSTAT='80R')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
	   if (@tempstat='90I' or FRMSTAT='90I')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @holdtime=@holdtime+date
 
OK i have shortened the code so that it fits and you can get the general drift sorry i'm such a newb.

Code:
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Rob,,Name>
-- Create date: <Create Date,,>
-- Description:	<SLR,,>
-- =============================================
CREATE PROCEDURE dbo.svcslr 
	-- Add the parameters for the stored procedure here
	(@callnbr char(11),
	 @startdate datetime,
	 @starttime datetime,
	 @enddate datetime,
	 @holdtime int output,
	 @worktime datetime output,
	 @flag int output,
	 @workingdate datetime,
	 @tempstat char(3)
	 )
	
as
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	set @workingdate=@startdate+@starttime
	set @tempstat='10E'
	set @worktime='0'
	SELECT [CALLNBR]
      ,[SRVRECTYPE]
      ,[LNITMSEQ]
      ,[FRMSTAT]
      ,[TOSTAT]
      ,[TECHID]
      ,[DSCRIPTN]
      ,[USERID]
      ,[CREATDDT]
      ,[CREATETIME]
      ,[DEX_ROW_ID]
	  if (@tempstat='04S' or FRMSTAT='04S')
			          Begin
	                     if TOSTAT='04S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='10E'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='20N'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50D'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='60A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='65A'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='00C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='30B'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='40M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='45I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='50O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
               	         if TOSTAT='70C'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='72P'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
                  	     if TOSTAT='74O'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='74S'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='75R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='78M'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='79U'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='80R'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
	                     if TOSTAT='90I'
							Begin
							set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
							end
		              END
   FROM [GP1].[dbo].[SVC00210]
  where CALLNBR=@callnbr
GO
 
IF is used to control code flow. If you want to control data, you should use case when.

You could also significantly reduce your code by using IN.

Case When (@tempstat='04S' or FRMSTAT='04S') And TOSTAT In ('04S','10E', etc....)



-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Dude, either stop taking those drugs now or share it with all of us!

all this code
Code:
Begin
set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
end

is the same for all those conditions

??????
keep that junk in a table then
Code:
if exists (select * from LookupLocalJunkValues where SomeCrazyColumnName = @tempstat)
begin
set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
end
else
begin
--do some other fancy stuff here
end



Denis The SQL Menace
--------------------
SQL Server Code,Tips and Tricks, Performance Tuning
SQLBlog.com, Google Interview Questions
 
Thank you george i have substantially reduced my code but it doesnt like my set statment in the case.

Dennis perhaps you might have a faster solution i am not aware of. I am working with two tables. the first is a list of tickets. the second is a list of status changes and times they took place keyed by the callnumber. basically certain status's stop my slr clock and others start it. at the end i will have the total time the ticket was in a stop the clock status and i will subtract that from the total time the ticket was open. there are sometimes 20-30 status changes on a given call and all are stored in the same table mixed with the status changes for all the other calls. I did not design the database but it is what i have to work with.
Code:
CREATE PROCEDURE dbo.svcslr 
	-- Add the parameters for the stored procedure here
	(@callnbr char(11),
	 @startdate datetime,
	 @starttime datetime,
	 @enddate datetime,
	 @holdtime int output,
	 @worktime datetime output,
	 @flag int output,
	 @workingdate datetime,
	 @tempstat char(3)
	 )
	
as
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	set @workingdate=@startdate+@starttime
	set @tempstat='10E'
	set @worktime='0'
	SELECT [CALLNBR]
      ,[SRVRECTYPE]
      ,[LNITMSEQ]
      ,[FRMSTAT]
      ,[TOSTAT]
      ,[TECHID]
      ,[DSCRIPTN]
      ,[USERID]
      ,[CREATDDT]
      ,[CREATETIME]
      ,[DEX_ROW_ID],
	Case When (@tempstat='04S' or FRMSTAT='04S') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
              Then set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
	END
	Case When (@tempstat='10E' or FRMSTAT='10E') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
              Then set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
	END
	Case When (@tempstat='20N' or FRMSTAT='20N') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
              Then set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
	END
	Case When (@tempstat='50D' or FRMSTAT='50D') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
              Then set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
	END
	Case When (@tempstat='60A' or FRMSTAT='60A') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
              Then set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime))
	END
	Case When (@tempstat='65A' or FRMSTAT='65A') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
              Then set @worktime=@worktime+datediff(n,@workingdate,(creatddt+createtime));
	END
	Case When (@tempstat='00C' or FRMSTAT='00C') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
			  Then set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
	END
	Case When (@tempstat='30B' or FRMSTAT='30B') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
			  Then set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
	END
	Case When (@tempstat='40M' or FRMSTAT='40M') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
			  Then set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
	END
	Case When (@tempstat='45I' or FRMSTAT='45I') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
			  Then set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
	END
	Case When (@tempstat='50O' or FRMSTAT='50O') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
			  Then set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
	END
	Case When (@tempstat='70C' or FRMSTAT='70C') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
			  Then set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
	END
	Case When (@tempstat='72P' or FRMSTAT='72P') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
			  Then set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
	END
	Case When (@tempstat='74I' or FRMSTAT='74I') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
			  Then set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
	END
	Case When (@tempstat='74O' or FRMSTAT='74O') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
			  Then set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
	END
	Case When (@tempstat='74S' or FRMSTAT='74S') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
			  Then set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
	END
	Case When (@tempstat='75R' or FRMSTAT='75R') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
			  Then set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
	END
	Case When (@tempstat='78M' or FRMSTAT='78M') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
			  Then set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
	END
	Case When (@tempstat='79U' or FRMSTAT='79U') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
			  Then set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
	END
	Case When (@tempstat='80R' or FRMSTAT='80R') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
			  Then set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
	END
	Case When (@tempstat='90I' or FRMSTAT='90I') And TOSTAT In ('04S','10E','20N','50D','60A','65A','00C','30B','40M','45I','50O','70C','72P','74I','74O','74S','75R','78M','79U','80R','90I')
			  Then set @holdtime=@holdtime+datediff(n,@workingdate,(creatddt+createtime));
	END
    FROM [GP1].[dbo].[SVC00210]
  where CALLNBR=@callnbr
GO
 
I think your query is, uh... I dunno. Weird.

Can you post some sample data and expected results? I think that will help us to help you.

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Yeah for sure here is the status change table data the column names are [CALLNBR],[SRVRECTYPE],[LNITMSEQ],[FRMSTAT],[TOSTAT],[TECHID],[DSCRIPTN],[USERID],[CREATDDT],[CREATETIME],[DEX_ROW_ID] this same table tracks the changes of the status for all calls so there will be about this many entrys for each call. this data is for one call each entry shows who changed the status of the ticket and from what to what status. Also the time it was changed.


0000019123 ,2,1, ,10E, ,Service Record Add/Update ,eConnect ,2008-02-12 00:00:00.000,1900-01-01 16:10:12.323,230760
0000019123 ,2,2,10E,10E,WY-SHILL ,Service Record Add/Update ,drobinson ,2008-02-12 00:00:00.000,1900-01-01 16:12:28.000,230767
0000019123 ,2,3, ,40M,WY-SHILL ,Service Record Add/Update ,eConnect ,2008-02-12 00:00:00.000,1900-01-01 16:55:14.283,230936
0000019123 ,2,4,40M,40M,WY-SHILL ,Service Record Add/Update ,drobinson ,2008-02-12 00:00:00.000,1900-01-01 18:35:49.000,231536
0000019123 ,2,5, ,10E,WY-SHILL ,Service Record Add/Update ,eConnect ,2008-02-12 00:00:00.000,1900-01-01 18:36:10.400,231540
0000019123 ,2,6, ,70C,WY-SHILL ,Service Record Add/Update ,eConnect ,2008-02-14 00:00:00.000,1900-01-01 09:58:47.527,234412
0000019123 ,2,7, ,40M,WY-SHILL ,Service Record Add/Update ,Case Exchange ,2008-03-11 00:00:00.000,1900-01-01 04:37:50.640,288549
0000019123 ,2,8, ,40M,WY-SHILL ,Service Record Add/Update ,Case Exchange ,2008-03-11 00:00:00.000,1900-01-01 04:37:51.423,288551
0000019123 ,2,9,40M,40M,WY-SHILL ,Service Record Add/Update ,aharris ,2008-03-11 00:00:00.000,1900-01-01 19:19:14.000,292573
0000019123 ,2,10, ,70C,WY-SHILL ,Service Record Add/Update ,eConnect ,2008-03-12 00:00:00.000,1900-01-01 12:26:36.607,293879
0000019123 ,2,11,70C,40M,WY-SHILL ,Service Record Add/Update ,drobinson ,2008-03-12 00:00:00.000,1900-01-01 12:35:53.000,293931
0000019123 ,2,12, ,40M,WY-SHILL ,Service Record Add/Update ,Case Exchange ,2008-03-12 00:00:00.000,1900-01-01 13:51:39.890,294569
0000019123 ,2,13, ,70C,WY-SHILL ,Service Record Add/Update ,eConnect ,2008-03-13 00:00:00.000,1900-01-01 09:12:16.343,298461
0000019123 ,2,14,70C,70C,WY-SHILL ,Service Record Add/Update ,aharris ,2008-03-13 00:00:00.000,1900-01-01 15:34:40.000,300358
0000019123 ,2,15, ,80R,WY-SHILL ,Service Record Add/Update ,Case Exchange ,2008-03-16 00:00:00.000,1900-01-01 15:37:39.077,306702
0000019123 ,2,16,80R,80R,WY-SHILL ,Updated userid on audit: 15 ,Case Exchange ,2008-03-16 00:00:00.000,1900-01-01 15:37:39.497,306703


the other table has the address and the call number and some other general information about the ticket. Also it tells me the amout of time we should have the ticket be it 4 days. however if a ticket needs parts we change the status to 30B and it doesnt count against our 4 days.
 
If I understand correctly, you want to return a HoldDuration and a WorkDuration from this data. These values should be calculated for the entire call (not a running total).

In order to effectively do this, I recommend a Self-Join query so that you can easily perform these calculations. A self join is really just a regular join, but it joins back to itself. When you do this, you must use table aliases.

You will see that the self join I use here assumes that LNITMSEQ is an integer column and that it is sequentially numbered (1, 2, 3, ....) and that there are no gaps in the sequence. If this is true, then you should not use the code I show you below, but in your final query, you could potentially use a table variable to get this numbering for you.

I'm gonna build this in stages for you so that it is easier to understand.

First, all the code I show below, uses a table variable to get the data from. If you are satisfied that the query works, all you should need to do is replace @Temp with your actual table name. Since the code I am posting uses a table variable, you can copy/paste this to Query Analyzer and run it (without any modifications) so that you can see HOW it works. Also, since it's all table variable stuff, it will not affect any real tables.

The basic self join....

Code:
[COLOR=blue]Declare[/color] @Temp 
[COLOR=blue]Table[/color]   ([CALLNBR] [COLOR=blue]VarChar[/color](20),[SRVRECTYPE] [COLOR=blue]Int[/color],[LNITMSEQ] [COLOR=blue]Int[/color],[FRMSTAT] [COLOR=blue]varchar[/color](3),[TOSTAT] [COLOR=blue]varchar[/color](3),
        [TECHID] [COLOR=blue]VarChar[/color](20),[DSCRIPTN] [COLOR=blue]VarChar[/color](200),[USERID] [COLOR=blue]VarChar[/color](20),[CREATDDT] [COLOR=#FF00FF]DateTime[/color],[CREATETIME] [COLOR=#FF00FF]DateTime[/color],[DEX_ROW_ID] [COLOR=blue]Int[/color])

[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'1'[/color],[COLOR=red]'   '[/color],[COLOR=red]'10E'[/color],[COLOR=red]'           '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 16:10:12.323'[/color],[COLOR=red]'230760'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'2'[/color],[COLOR=red]'10E'[/color],[COLOR=red]'10E'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'drobinson      '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 16:12:28.000'[/color],[COLOR=red]'230767'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'3'[/color],[COLOR=red]'   '[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 16:55:14.283'[/color],[COLOR=red]'230936'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'4'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'drobinson      '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 18:35:49.000'[/color],[COLOR=red]'231536'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'5'[/color],[COLOR=red]'   '[/color],[COLOR=red]'10E'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 18:36:10.400'[/color],[COLOR=red]'231540'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'6'[/color],[COLOR=red]'   '[/color],[COLOR=red]'70C'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-02-14 00:00:00.000'[/color],[COLOR=red]'1900-01-01 09:58:47.527'[/color],[COLOR=red]'234412'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'7'[/color],[COLOR=red]'   '[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-11 00:00:00.000'[/color],[COLOR=red]'1900-01-01 04:37:50.640'[/color],[COLOR=red]'288549'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'8'[/color],[COLOR=red]'   '[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-11 00:00:00.000'[/color],[COLOR=red]'1900-01-01 04:37:51.423'[/color],[COLOR=red]'288551'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'9'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'aharris        '[/color],[COLOR=red]'2008-03-11 00:00:00.000'[/color],[COLOR=red]'1900-01-01 19:19:14.000'[/color],[COLOR=red]'292573'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'10'[/color],[COLOR=red]'   '[/color],[COLOR=red]'70C'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-03-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 12:26:36.607'[/color],[COLOR=red]'293879'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'11'[/color],[COLOR=red]'70C'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'drobinson      '[/color],[COLOR=red]'2008-03-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 12:35:53.000'[/color],[COLOR=red]'293931'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'12'[/color],[COLOR=red]'   '[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 13:51:39.890'[/color],[COLOR=red]'294569'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'13'[/color],[COLOR=red]'   '[/color],[COLOR=red]'70C'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-03-13 00:00:00.000'[/color],[COLOR=red]'1900-01-01 09:12:16.343'[/color],[COLOR=red]'298461'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'14'[/color],[COLOR=red]'70C'[/color],[COLOR=red]'70C'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'aharris        '[/color],[COLOR=red]'2008-03-13 00:00:00.000'[/color],[COLOR=red]'1900-01-01 15:34:40.000'[/color],[COLOR=red]'300358'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'15'[/color],[COLOR=red]'   '[/color],[COLOR=red]'80R'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-16 00:00:00.000'[/color],[COLOR=red]'1900-01-01 15:37:39.077'[/color],[COLOR=red]'306702'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'16'[/color],[COLOR=red]'80R'[/color],[COLOR=red]'80R'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Updated userid on audit: 15    '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-16 00:00:00.000'[/color],[COLOR=red]'1900-01-01 15:37:39.497'[/color],[COLOR=red]'306703'[/color])

[COLOR=blue]Select[/color]  A.LNITMSEQ,
        A.CreatDDT + A.CreateTime [COLOR=blue]As[/color] FromTime,
        B.CreatDDT + B.CreateTime [COLOR=blue]As[/color] ToTime
[COLOR=blue]From[/color]    @Temp A
        [COLOR=blue]Inner[/color] [COLOR=blue]Join[/color] @Temp B
          [COLOR=blue]On[/color] A.CallNbr = B.CallNbr
          And A.LNITMSEQ = B.LNITMSEQ - 1

When you run this code, you will see that the sequence number is returned as well as the call time. With both times in the same row, it becomes easy to perform calculations. Like this...

Code:
[COLOR=blue]Declare[/color] @Temp 
[COLOR=blue]Table[/color]   ([CALLNBR] [COLOR=blue]VarChar[/color](20),[SRVRECTYPE] [COLOR=blue]Int[/color],[LNITMSEQ] [COLOR=blue]Int[/color],[FRMSTAT] [COLOR=blue]varchar[/color](3),[TOSTAT] [COLOR=blue]varchar[/color](3),
        [TECHID] [COLOR=blue]VarChar[/color](20),[DSCRIPTN] [COLOR=blue]VarChar[/color](200),[USERID] [COLOR=blue]VarChar[/color](20),[CREATDDT] [COLOR=#FF00FF]DateTime[/color],[CREATETIME] [COLOR=#FF00FF]DateTime[/color],[DEX_ROW_ID] [COLOR=blue]Int[/color])

[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'1'[/color],[COLOR=red]'   '[/color],[COLOR=red]'10E'[/color],[COLOR=red]'           '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 16:10:12.323'[/color],[COLOR=red]'230760'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'2'[/color],[COLOR=red]'10E'[/color],[COLOR=red]'10E'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'drobinson      '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 16:12:28.000'[/color],[COLOR=red]'230767'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'3'[/color],[COLOR=red]'   '[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 16:55:14.283'[/color],[COLOR=red]'230936'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'4'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'drobinson      '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 18:35:49.000'[/color],[COLOR=red]'231536'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'5'[/color],[COLOR=red]'   '[/color],[COLOR=red]'10E'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 18:36:10.400'[/color],[COLOR=red]'231540'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'6'[/color],[COLOR=red]'   '[/color],[COLOR=red]'70C'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-02-14 00:00:00.000'[/color],[COLOR=red]'1900-01-01 09:58:47.527'[/color],[COLOR=red]'234412'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'7'[/color],[COLOR=red]'   '[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-11 00:00:00.000'[/color],[COLOR=red]'1900-01-01 04:37:50.640'[/color],[COLOR=red]'288549'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'8'[/color],[COLOR=red]'   '[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-11 00:00:00.000'[/color],[COLOR=red]'1900-01-01 04:37:51.423'[/color],[COLOR=red]'288551'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'9'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'aharris        '[/color],[COLOR=red]'2008-03-11 00:00:00.000'[/color],[COLOR=red]'1900-01-01 19:19:14.000'[/color],[COLOR=red]'292573'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'10'[/color],[COLOR=red]'   '[/color],[COLOR=red]'70C'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-03-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 12:26:36.607'[/color],[COLOR=red]'293879'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'11'[/color],[COLOR=red]'70C'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'drobinson      '[/color],[COLOR=red]'2008-03-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 12:35:53.000'[/color],[COLOR=red]'293931'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'12'[/color],[COLOR=red]'   '[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 13:51:39.890'[/color],[COLOR=red]'294569'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'13'[/color],[COLOR=red]'   '[/color],[COLOR=red]'70C'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-03-13 00:00:00.000'[/color],[COLOR=red]'1900-01-01 09:12:16.343'[/color],[COLOR=red]'298461'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'14'[/color],[COLOR=red]'70C'[/color],[COLOR=red]'70C'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'aharris        '[/color],[COLOR=red]'2008-03-13 00:00:00.000'[/color],[COLOR=red]'1900-01-01 15:34:40.000'[/color],[COLOR=red]'300358'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'15'[/color],[COLOR=red]'   '[/color],[COLOR=red]'80R'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-16 00:00:00.000'[/color],[COLOR=red]'1900-01-01 15:37:39.077'[/color],[COLOR=red]'306702'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'16'[/color],[COLOR=red]'80R'[/color],[COLOR=red]'80R'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Updated userid on audit: 15    '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-16 00:00:00.000'[/color],[COLOR=red]'1900-01-01 15:37:39.497'[/color],[COLOR=red]'306703'[/color])

[COLOR=blue]Select[/color]  A.LNITMSEQ,
        A.CreatDDT + A.CreateTime [COLOR=blue]As[/color] FromTime,
        B.CreatDDT + B.CreateTime [COLOR=blue]As[/color] ToTime,
        [COLOR=#FF00FF]DateDiff[/color]([COLOR=#FF00FF]Minute[/color], A.CreatDDT + A.CreateTime, B.CreatDDT + B.CreateTime) [COLOR=blue]As[/color] [Durations(Minutes)]
[COLOR=blue]From[/color]    @Temp A
        [COLOR=blue]Inner[/color] [COLOR=blue]Join[/color] @Temp B
          [COLOR=blue]On[/color] A.CallNbr = B.CallNbr
          And A.LNITMSEQ = B.LNITMSEQ - 1

Now, we need to apply your filters, right?

Code:
[COLOR=blue]Declare[/color] @Temp 
[COLOR=blue]Table[/color]   ([CALLNBR] [COLOR=blue]VarChar[/color](20),[SRVRECTYPE] [COLOR=blue]Int[/color],[LNITMSEQ] [COLOR=blue]Int[/color],[FRMSTAT] [COLOR=blue]varchar[/color](3),[TOSTAT] [COLOR=blue]varchar[/color](3),
        [TECHID] [COLOR=blue]VarChar[/color](20),[DSCRIPTN] [COLOR=blue]VarChar[/color](200),[USERID] [COLOR=blue]VarChar[/color](20),[CREATDDT] [COLOR=#FF00FF]DateTime[/color],[CREATETIME] [COLOR=#FF00FF]DateTime[/color],[DEX_ROW_ID] [COLOR=blue]Int[/color])

[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'1'[/color],[COLOR=red]'   '[/color],[COLOR=red]'10E'[/color],[COLOR=red]'           '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 16:10:12.323'[/color],[COLOR=red]'230760'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'2'[/color],[COLOR=red]'10E'[/color],[COLOR=red]'10E'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'drobinson      '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 16:12:28.000'[/color],[COLOR=red]'230767'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'3'[/color],[COLOR=red]'   '[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 16:55:14.283'[/color],[COLOR=red]'230936'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'4'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'drobinson      '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 18:35:49.000'[/color],[COLOR=red]'231536'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'5'[/color],[COLOR=red]'   '[/color],[COLOR=red]'10E'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 18:36:10.400'[/color],[COLOR=red]'231540'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'6'[/color],[COLOR=red]'   '[/color],[COLOR=red]'70C'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-02-14 00:00:00.000'[/color],[COLOR=red]'1900-01-01 09:58:47.527'[/color],[COLOR=red]'234412'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'7'[/color],[COLOR=red]'   '[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-11 00:00:00.000'[/color],[COLOR=red]'1900-01-01 04:37:50.640'[/color],[COLOR=red]'288549'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'8'[/color],[COLOR=red]'   '[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-11 00:00:00.000'[/color],[COLOR=red]'1900-01-01 04:37:51.423'[/color],[COLOR=red]'288551'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'9'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'aharris        '[/color],[COLOR=red]'2008-03-11 00:00:00.000'[/color],[COLOR=red]'1900-01-01 19:19:14.000'[/color],[COLOR=red]'292573'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'10'[/color],[COLOR=red]'   '[/color],[COLOR=red]'70C'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-03-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 12:26:36.607'[/color],[COLOR=red]'293879'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'11'[/color],[COLOR=red]'70C'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'drobinson      '[/color],[COLOR=red]'2008-03-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 12:35:53.000'[/color],[COLOR=red]'293931'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'12'[/color],[COLOR=red]'   '[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 13:51:39.890'[/color],[COLOR=red]'294569'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'13'[/color],[COLOR=red]'   '[/color],[COLOR=red]'70C'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-03-13 00:00:00.000'[/color],[COLOR=red]'1900-01-01 09:12:16.343'[/color],[COLOR=red]'298461'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'14'[/color],[COLOR=red]'70C'[/color],[COLOR=red]'70C'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'aharris        '[/color],[COLOR=red]'2008-03-13 00:00:00.000'[/color],[COLOR=red]'1900-01-01 15:34:40.000'[/color],[COLOR=red]'300358'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'15'[/color],[COLOR=red]'   '[/color],[COLOR=red]'80R'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-16 00:00:00.000'[/color],[COLOR=red]'1900-01-01 15:37:39.077'[/color],[COLOR=red]'306702'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'16'[/color],[COLOR=red]'80R'[/color],[COLOR=red]'80R'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Updated userid on audit: 15    '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-16 00:00:00.000'[/color],[COLOR=red]'1900-01-01 15:37:39.497'[/color],[COLOR=red]'306703'[/color])

[COLOR=blue]Select[/color]  A.CreatDDT + A.CreateTime [COLOR=blue]As[/color] FromTime,
        B.CreatDDT + B.CreateTime [COLOR=blue]As[/color] ToTime,
        [COLOR=blue]Case[/color] [COLOR=blue]When[/color] A.FRMSTAT In([COLOR=red]'00C'[/color],[COLOR=red]'30B'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'45I'[/color],[COLOR=red]'50O'[/color],[COLOR=red]'70C'[/color],[COLOR=red]'72P'[/color],[COLOR=red]'74I'[/color],[COLOR=red]'74O'[/color],[COLOR=red]'74S'[/color],[COLOR=red]'75R'[/color],[COLOR=red]'78M'[/color],[COLOR=red]'79U'[/color],[COLOR=red]'80R'[/color],[COLOR=red]'90I'[/color])
             [COLOR=blue]Then[/color] [COLOR=#FF00FF]DateDiff[/color]([COLOR=#FF00FF]Minute[/color], A.CreatDDT + A.CreateTime, B.CreatDDT + B.CreateTime)
             [COLOR=blue]Else[/color] 0 [COLOR=blue]End[/color] [COLOR=blue]As[/color] HoldDuration,
        [COLOR=blue]Case[/color] [COLOR=blue]When[/color] A.FRMSTAT IN([COLOR=red]'04S'[/color],[COLOR=red]'10E'[/color],[COLOR=red]'20N'[/color],[COLOR=red]'50D'[/color],[COLOR=red]'60A'[/color],[COLOR=red]'65A'[/color])
             [COLOR=blue]Then[/color] [COLOR=#FF00FF]DateDiff[/color]([COLOR=#FF00FF]Minute[/color], A.CreatDDT + A.CreateTime, B.CreatDDT + B.CreateTime)
             [COLOR=blue]Else[/color] 0 [COLOR=blue]End[/color] [COLOR=blue]As[/color] WorkDuration
[COLOR=blue]From[/color]    @Temp A
        [COLOR=blue]Inner[/color] [COLOR=blue]Join[/color] @Temp B
            [COLOR=blue]On[/color] A.CallNbr = B.CallNbr
            And A.LNITMSEQ = B.LNITMSEQ - 1
[COLOR=blue]Where[/color]   A.TOSTAT In ([COLOR=red]'04S'[/color],[COLOR=red]'10E'[/color],[COLOR=red]'20N'[/color],[COLOR=red]'50D'[/color],[COLOR=red]'60A'[/color],[COLOR=red]'65A'[/color],[COLOR=red]'00C'[/color],[COLOR=red]'30B'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'45I'[/color],[COLOR=red]'50O'[/color],[COLOR=red]'70C'[/color],[COLOR=red]'72P'[/color],[COLOR=red]'74I'[/color],[COLOR=red]'74O'[/color],[COLOR=red]'74S'[/color],[COLOR=red]'75R'[/color],[COLOR=red]'78M'[/color],[COLOR=red]'79U'[/color],[COLOR=red]'80R'[/color],[COLOR=red]'90I'[/color])

Really... the only other thing we need to do is to add up the durations to get your totals. Like this...

Code:
[COLOR=blue]Declare[/color] @Temp 
[COLOR=blue]Table[/color]   ([CALLNBR] [COLOR=blue]VarChar[/color](20),[SRVRECTYPE] [COLOR=blue]Int[/color],[LNITMSEQ] [COLOR=blue]Int[/color],[FRMSTAT] [COLOR=blue]varchar[/color](3),[TOSTAT] [COLOR=blue]varchar[/color](3),
        [TECHID] [COLOR=blue]VarChar[/color](20),[DSCRIPTN] [COLOR=blue]VarChar[/color](200),[USERID] [COLOR=blue]VarChar[/color](20),[CREATDDT] [COLOR=#FF00FF]DateTime[/color],[CREATETIME] [COLOR=#FF00FF]DateTime[/color],[DEX_ROW_ID] [COLOR=blue]Int[/color])

[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'1'[/color],[COLOR=red]'   '[/color],[COLOR=red]'10E'[/color],[COLOR=red]'           '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 16:10:12.323'[/color],[COLOR=red]'230760'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'2'[/color],[COLOR=red]'10E'[/color],[COLOR=red]'10E'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'drobinson      '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 16:12:28.000'[/color],[COLOR=red]'230767'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'3'[/color],[COLOR=red]'   '[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 16:55:14.283'[/color],[COLOR=red]'230936'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'4'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'drobinson      '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 18:35:49.000'[/color],[COLOR=red]'231536'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'5'[/color],[COLOR=red]'   '[/color],[COLOR=red]'10E'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-02-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 18:36:10.400'[/color],[COLOR=red]'231540'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'6'[/color],[COLOR=red]'   '[/color],[COLOR=red]'70C'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-02-14 00:00:00.000'[/color],[COLOR=red]'1900-01-01 09:58:47.527'[/color],[COLOR=red]'234412'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'7'[/color],[COLOR=red]'   '[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-11 00:00:00.000'[/color],[COLOR=red]'1900-01-01 04:37:50.640'[/color],[COLOR=red]'288549'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'8'[/color],[COLOR=red]'   '[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-11 00:00:00.000'[/color],[COLOR=red]'1900-01-01 04:37:51.423'[/color],[COLOR=red]'288551'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'9'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'aharris        '[/color],[COLOR=red]'2008-03-11 00:00:00.000'[/color],[COLOR=red]'1900-01-01 19:19:14.000'[/color],[COLOR=red]'292573'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'10'[/color],[COLOR=red]'   '[/color],[COLOR=red]'70C'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-03-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 12:26:36.607'[/color],[COLOR=red]'293879'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'11'[/color],[COLOR=red]'70C'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'drobinson      '[/color],[COLOR=red]'2008-03-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 12:35:53.000'[/color],[COLOR=red]'293931'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'12'[/color],[COLOR=red]'   '[/color],[COLOR=red]'40M'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-12 00:00:00.000'[/color],[COLOR=red]'1900-01-01 13:51:39.890'[/color],[COLOR=red]'294569'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'13'[/color],[COLOR=red]'   '[/color],[COLOR=red]'70C'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'eConnect       '[/color],[COLOR=red]'2008-03-13 00:00:00.000'[/color],[COLOR=red]'1900-01-01 09:12:16.343'[/color],[COLOR=red]'298461'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'14'[/color],[COLOR=red]'70C'[/color],[COLOR=red]'70C'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'aharris        '[/color],[COLOR=red]'2008-03-13 00:00:00.000'[/color],[COLOR=red]'1900-01-01 15:34:40.000'[/color],[COLOR=red]'300358'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'15'[/color],[COLOR=red]'   '[/color],[COLOR=red]'80R'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Service Record Add/Update      '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-16 00:00:00.000'[/color],[COLOR=red]'1900-01-01 15:37:39.077'[/color],[COLOR=red]'306702'[/color])
[COLOR=blue]Insert[/color] [COLOR=blue]Into[/color] @Temp [COLOR=blue]Values[/color]([COLOR=red]'0000019123 '[/color],[COLOR=red]'2'[/color],[COLOR=red]'16'[/color],[COLOR=red]'80R'[/color],[COLOR=red]'80R'[/color],[COLOR=red]'WY-SHILL   '[/color],[COLOR=red]'Updated userid on audit: 15    '[/color],[COLOR=red]'Case Exchange  '[/color],[COLOR=red]'2008-03-16 00:00:00.000'[/color],[COLOR=red]'1900-01-01 15:37:39.497'[/color],[COLOR=red]'306703'[/color])

[COLOR=blue]Select[/color]  A.CALLNBR,
        Sum([COLOR=blue]Case[/color] [COLOR=blue]When[/color] A.FRMSTAT In([COLOR=red]'00C'[/color],[COLOR=red]'30B'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'45I'[/color],[COLOR=red]'50O'[/color],[COLOR=red]'70C'[/color],[COLOR=red]'72P'[/color],[COLOR=red]'74I'[/color],[COLOR=red]'74O'[/color],[COLOR=red]'74S'[/color],[COLOR=red]'75R'[/color],[COLOR=red]'78M'[/color],[COLOR=red]'79U'[/color],[COLOR=red]'80R'[/color],[COLOR=red]'90I'[/color])
             [COLOR=blue]Then[/color] [COLOR=#FF00FF]DateDiff[/color]([COLOR=#FF00FF]Minute[/color], A.CreatDDT + A.CreateTime, B.CreatDDT + B.CreateTime)
             [COLOR=blue]Else[/color] 0 [COLOR=blue]End[/color]) [COLOR=blue]As[/color] HoldDuration,
        Sum([COLOR=blue]Case[/color] [COLOR=blue]When[/color] A.FRMSTAT IN([COLOR=red]'04S'[/color],[COLOR=red]'10E'[/color],[COLOR=red]'20N'[/color],[COLOR=red]'50D'[/color],[COLOR=red]'60A'[/color],[COLOR=red]'65A'[/color])
             [COLOR=blue]Then[/color] [COLOR=#FF00FF]DateDiff[/color]([COLOR=#FF00FF]Minute[/color], A.CreatDDT + A.CreateTime, B.CreatDDT + B.CreateTime)
             [COLOR=blue]Else[/color] 0 [COLOR=blue]End[/color]) [COLOR=blue]As[/color] WorkDuration
[COLOR=blue]From[/color]    @Temp A
        [COLOR=blue]Inner[/color] [COLOR=blue]Join[/color] @Temp B
            [COLOR=blue]On[/color] A.CallNbr = B.CallNbr
            And A.LNITMSEQ = B.LNITMSEQ - 1
[COLOR=blue]Where[/color]   A.TOSTAT In ([COLOR=red]'04S'[/color],[COLOR=red]'10E'[/color],[COLOR=red]'20N'[/color],[COLOR=red]'50D'[/color],[COLOR=red]'60A'[/color],[COLOR=red]'65A'[/color],[COLOR=red]'00C'[/color],[COLOR=red]'30B'[/color],[COLOR=red]'40M'[/color],[COLOR=red]'45I'[/color],[COLOR=red]'50O'[/color],[COLOR=red]'70C'[/color],[COLOR=red]'72P'[/color],[COLOR=red]'74I'[/color],[COLOR=red]'74O'[/color],[COLOR=red]'74S'[/color],[COLOR=red]'75R'[/color],[COLOR=red]'78M'[/color],[COLOR=red]'79U'[/color],[COLOR=red]'80R'[/color],[COLOR=red]'90I'[/color])
[COLOR=blue]Group[/color] [COLOR=blue]By[/color] A.CALLNBR

If this works for you, then I strongly encourage you to study it in depth. If there is anything that you don't understand, don't hesitate to ask.

Make sense?

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Ohh this paticualr ticket was put to 40m that means we are waiting on the customer. this again is not counted against our service level requirments. let me know if there is anything else i can provide.
 
Correction:

In my previous post, I should have said.

[tt][blue]You will see that the self join I use here assumes that LNITMSEQ is an integer column and that it is sequentially numbered (1, 2, 3, ....) and that there are no gaps in the sequence. If this is [!]Not[/!] true, then you should not use the code I show you below, but in your final query, you could potentially use a table variable to get this numbering for you.[/blue][/tt]


If LNITMSEQ is sequential, then it makes the query easier because you don't need to worry about the sequence numbers. If you cannot guarantee this ordering, then you need to 'work a little harder'. I apologize for any confusion this may have caused.


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
OHHH MY George you are the man i really hope someday i can help you out!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top