IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[_depurarSesiones]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[_depurarSesiones]
GO
CREATE PROCEDURE  [dbo].[_depurarSesiones]	
as begin
INSERT INTO [dbo].[seg_sesionHistorico]
           ([id]
           ,[uid]
           ,[eid]
           ,[id_usuario_modifico]
           ,[id_usuario_creo]
           ,[fechaModificacion]
           ,[fechaCreacion]
           ,[active]
           ,[sesion]
           ,[sesion_codigo])
SELECT [id]
      ,[uid]
      ,[eid]
      ,[id_usuario_modifico]
      ,[id_usuario_creo]
      ,[fechaModificacion]
      ,[fechaCreacion]
      ,[active]
      ,[sesion]
      ,[sesion_codigo]
from seg_sesion where sesion ='ok' and id>0
delete from seg_sesion  where sesion ='ok' and id>0
end 