DECLARE @Count INT

SELECT @Count = COUNT(*) FROM ArrangementLines WITH (NOLOCK) WHERE ISNULL(TimeDT, 0) = 0  AND (Time <> '00:00')

IF @Count > 0
BEGIN
  IF EXISTS (SELECT * FROM dbo.SysObjects WHERE id = object_id(N'dbo.ArrangementLineIllegalWare') AND OBJECTPROPERTY(id, N'IsTrigger') = 1)
    DISABLE TRIGGER ArrangementLineIllegalWare ON dbo.ArrangementLines

  DECLARE @ArrLineNumber INT
  DECLARE @Time CHAR(5)

  DECLARE ArrTimeDTCursor CURSOR FOR
    SELECT ArrangementLineNumber, Time FROM ArrangementLines WITH (NOLOCK) WHERE ISNULL(TimeDT, 0) = 0

  OPEN ArrTimeDTCursor
  FETCH NEXT FROM ArrTimeDTCursor INTO @ArrLineNumber, @Time
  WHILE (@@FETCH_STATUS <> -1)
  BEGIN
    
	UPDATE ArrangementLines
    SET TimeDT  = CONVERT(datetime, Time, 108)
	WHERE ArrangementLineNumber = @ArrLineNumber

    FETCH NEXT FROM ArrTimeDTCursor INTO @ArrLineNumber, @Time
  END

  IF EXISTS (SELECT * FROM dbo.SysObjects WHERE id = object_id(N'dbo.ArrangementLineIllegalWare') AND OBJECTPROPERTY(id, N'IsTrigger') = 1)
    ENABLE TRIGGER ArrangementLineIllegalWare ON dbo.ArrangementLines

  CLOSE ArrTimeDTCursor
  DEALLOCATE ArrTimeDTCursor
END
