

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_doc_subtipoDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_doc_subtipoDocumento]
GO
CREATE PROCEDURE [reg_doc_subtipoDocumento]
	@p_id INT
AS
BEGIN
	SELECT 	[id] AS [id],
		[uid] AS [uid],
		[eid] AS [eid],
		[id_usuario_modifico] AS [id_usuario_modifico],
		[id_usuario_creo] AS [id_usuario_creo],
		[fechaModificacion] AS [fechaModificacion],
		[fechaCreacion] AS [fechaCreacion],
		[active] AS [active],
		[subtipoDocumento] AS [subtipoDocumento],
		[subtipoDocumento_codigo] AS [subtipoDocumento_codigo],
		[prefijo] AS [prefijo],
		[consecutivo] AS [consecutivo],
		[id_tipoDocumento] AS [id_tipoDocumento],
		[programarPlaneadas] AS [programarPlaneadas]
	FROM [doc_subtipoDocumento]
	WHERE	(id = @p_id)

END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[view_doc_subtipoDocumento]')) DROP VIEW [dbo].[view_doc_subtipoDocumento]
GO
CREATE  VIEW [view_doc_subtipoDocumento] AS
SELECT 	[doc_subtipoDocumento].[id] AS [id],
		[doc_subtipoDocumento].[uid] AS [uid],
		[doc_subtipoDocumento].[eid] AS [eid],
		[doc_subtipoDocumento].[id_usuario_modifico] AS [id_usuario_modifico],
		[doc_subtipoDocumento].[id_usuario_creo] AS [id_usuario_creo],
		[doc_subtipoDocumento].[fechaModificacion] AS [fechaModificacion],
		[doc_subtipoDocumento].[fechaCreacion] AS [fechaCreacion],
		[doc_subtipoDocumento].[active] AS [active],
		[doc_subtipoDocumento].[subtipoDocumento] AS [subtipoDocumento],
		[doc_subtipoDocumento].[subtipoDocumento_codigo] AS [subtipoDocumento_codigo],
		[doc_subtipoDocumento].[prefijo] AS [prefijo],
		[doc_subtipoDocumento].[consecutivo] AS [consecutivo],
		[doc_subtipoDocumento].[id_tipoDocumento] AS [id_tipoDocumento],
[doc_tipoDocumento].[tipoDocumento] as [doc_tipoDocumento_tipoDocumento],
[doc_tipoDocumento].[tipoDocumento_codigo] as [doc_tipoDocumento_tipoDocumento_codigo],
[doc_tipoDocumento].[esSalida] as [doc_tipoDocumento_esSalida],
[doc_tipoDocumento].[mostrarBodega] as [doc_tipoDocumento_mostrarBodega],
[doc_tipoDocumento].[mostrarCentroCosto] as [doc_tipoDocumento_mostrarCentroCosto],
[doc_tipoDocumento].[mostrarIncoterm] as [doc_tipoDocumento_mostrarIncoterm],
[doc_tipoDocumento].[puedeSerMayor] as [doc_tipoDocumento_puedeSerMayor],
[doc_tipoDocumento].[puedeSerMenor] as [doc_tipoDocumento_puedeSerMenor],
		[doc_subtipoDocumento].[programarPlaneadas] AS [programarPlaneadas],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [doc_subtipoDocumento]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[doc_subtipoDocumento].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[doc_subtipoDocumento].[id_usuario_creo]
	INNER JOIN [doc_tipoDocumento] ON [doc_tipoDocumento].id=[doc_subtipoDocumento].[id_tipoDocumento]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [doc_subtipoDocumento].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [doc_subtipoDocumento].active=1
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_doc_subtipoDocumentosXusuario_modifico]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_subtipoDocumentosXusuario_modifico]
GO
CREATE PROCEDURE [sel_doc_subtipoDocumentosXusuario_modifico]
	@p_id_usuario_modifico INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_subtipoDocumento]
	WHERE ([id_usuario_modifico]= @p_id_usuario_modifico)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_doc_subtipoDocumentosXusuario_creo]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_subtipoDocumentosXusuario_creo]
GO
CREATE PROCEDURE [sel_doc_subtipoDocumentosXusuario_creo]
	@p_id_usuario_creo INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_subtipoDocumento]
	WHERE ([id_usuario_creo]= @p_id_usuario_creo)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_doc_subtipoDocumentosXtipoDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_subtipoDocumentosXtipoDocumento]
GO
CREATE PROCEDURE [sel_doc_subtipoDocumentosXtipoDocumento]
	@p_id_tipoDocumento INT
AS
BEGIN
	SELECT * 
	FROM [view_doc_subtipoDocumento]
	WHERE ([id_tipoDocumento]= @p_id_tipoDocumento)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_doc_subtipoDocumentos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_subtipoDocumentos]
GO
CREATE PROCEDURE [sel_doc_subtipoDocumentos]
	
	@p_filtro as varchar (8000) = '1=1',
	@p_orden as varchar (8000) = 'id',
	@p_campos as varchar (8000) = '*' AS
BEGIN
exec ('SELECT '+ @p_campos +
' FROM [view_doc_subtipoDocumento]
WHERE (' + @p_filtro + ') ORDER BY ' + @p_orden)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[lis_doc_subtipoDocumentos]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_doc_subtipoDocumentos]
GO
CREATE PROCEDURE [lis_doc_subtipoDocumentos]
	AS
BEGIN
	SELECT id AS id,
[subtipoDocumento] AS [doc_subtipoDocumento]
	FROM [doc_subtipoDocumento]
	WHERE active = 1
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[upd_doc_subtipoDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_doc_subtipoDocumento]
GO
CREATE PROCEDURE [upd_doc_subtipoDocumento]
	@p_id int = null,
		@p_uid varchar(500) = null,
		@p_eid varchar(50) = null,
		@p_id_usuario_modifico int = null,
		@p_id_usuario_creo int = null,
		@p_fechaCreacion smalldatetime = null,
		@p_subtipoDocumento varchar(300) = null,
		@p_subtipoDocumento_codigo varchar(100) = null,
		@p_prefijo varchar(10) = null,
		@p_consecutivo int = null,
		@p_id_tipoDocumento int = null,
		@p_programarPlaneadas bit = null
AS
BEGIN
		UPDATE [doc_subtipoDocumento]
		SET	[uid] = isnull(@p_uid,[uid]),
			[eid] = isnull(@p_eid,[eid]),
			[id_usuario_modifico] = isnull(@p_id_usuario_modifico,[id_usuario_modifico]),
			[id_usuario_creo] = isnull(@p_id_usuario_creo,[id_usuario_creo]),
			[fechaModificacion] = GETDATE(),
			[subtipoDocumento] = isnull(@p_subtipoDocumento,[subtipoDocumento]),
			[subtipoDocumento_codigo] = isnull(@p_subtipoDocumento_codigo,[subtipoDocumento_codigo]),
			[prefijo] = isnull(@p_prefijo,[prefijo]),
			[consecutivo] = isnull(@p_consecutivo,[consecutivo]),
			[id_tipoDocumento] = isnull(@p_id_tipoDocumento,[id_tipoDocumento]),
			[programarPlaneadas] = isnull(@p_programarPlaneadas,[programarPlaneadas])
		WHERE (id = @p_id)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ins_doc_subtipoDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_doc_subtipoDocumento]
GO
CREATE PROCEDURE [ins_doc_subtipoDocumento]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_subtipoDocumento varchar(300),
		@p_subtipoDocumento_codigo varchar(100),
		@p_prefijo varchar(10),
		@p_consecutivo int,
		@p_id_tipoDocumento int,
		@p_programarPlaneadas bit
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [doc_subtipoDocumento]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[subtipoDocumento],
			[subtipoDocumento_codigo],
			[prefijo],
			[consecutivo],
			[id_tipoDocumento],
			[programarPlaneadas])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_subtipoDocumento,
			@p_subtipoDocumento_codigo,
			@p_prefijo,
			@p_consecutivo,
			@p_id_tipoDocumento,
			@p_programarPlaneadas)
		SET @v_id = scope_identity()
UPDATE [doc_subtipoDocumento] set [uid] = [uid] + '_' + convert(varchar(20),@v_id) where [id]=@v_id
SELECT @v_id as id
RETURN @v_id
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[act_doc_subtipoDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[act_doc_subtipoDocumento]
GO
CREATE PROCEDURE [act_doc_subtipoDocumento]
	@p_active BIT,
	@p_id INT,
@p_id_usuario_modifico int = null
AS
BEGIN
	UPDATE [doc_subtipoDocumento]
	SET active=@p_active,
	[id_usuario_modifico] = isnull(@p_id_usuario_modifico,[id_usuario_modifico]),
	[fechaModificacion] = GETDATE()
	WHERE	(id = @p_id)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[reg_doc_subtipoDocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[reg_doc_subtipoDocumento_m]
GO
CREATE PROCEDURE [reg_doc_subtipoDocumento_m]
	@p_id INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT 	[id] AS [id],
		[uid] AS [uid],
		[eid] AS [eid],
		[id_usuario_modifico] AS [id_usuario_modifico],
		[id_usuario_creo] AS [id_usuario_creo],
		[fechaModificacion] AS [fechaModificacion],
		[fechaCreacion] AS [fechaCreacion],
		[active] AS [active],
		[subtipoDocumento] AS [subtipoDocumento],
		[subtipoDocumento_codigo] AS [subtipoDocumento_codigo],
		[prefijo] AS [prefijo],
		[consecutivo] AS [consecutivo],
		[id_tipoDocumento] AS [id_tipoDocumento],
		[programarPlaneadas] AS [programarPlaneadas]
	FROM [doc_subtipoDocumento]
	WHERE	(id = @p_id)
	AND	(eid LIKE @p_eid+'%')

END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_doc_subtipoDocumentosXusuario_modifico_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_subtipoDocumentosXusuario_modifico_m]
GO
CREATE PROCEDURE [sel_doc_subtipoDocumentosXusuario_modifico_m]
	@p_id_usuario_modifico INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_subtipoDocumento]
	WHERE ([id_usuario_modifico]= @p_id_usuario_modifico)
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_doc_subtipoDocumentosXusuario_creo_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_subtipoDocumentosXusuario_creo_m]
GO
CREATE PROCEDURE [sel_doc_subtipoDocumentosXusuario_creo_m]
	@p_id_usuario_creo INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_subtipoDocumento]
	WHERE ([id_usuario_creo]= @p_id_usuario_creo)
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_doc_subtipoDocumentosXtipoDocumento_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_subtipoDocumentosXtipoDocumento_m]
GO
CREATE PROCEDURE [sel_doc_subtipoDocumentosXtipoDocumento_m]
	@p_id_tipoDocumento INT,
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT *
	FROM [view_doc_subtipoDocumento]
	WHERE ([id_tipoDocumento]= @p_id_tipoDocumento)
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_doc_subtipoDocumentos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_subtipoDocumentos_m]
GO
CREATE PROCEDURE [sel_doc_subtipoDocumentos_m]
	@p_eid as varchar (50)='',
	@p_filtro as varchar (8000) = '1=1',
	@p_orden as varchar (8000) = 'id',
	@p_campos as varchar (8000) = '*' AS
BEGIN
exec ('SELECT '+ @p_campos +
' FROM [view_doc_subtipoDocumento]
WHERE  (eid like '''+@p_eid+'%'+''' ) AND (' + @p_filtro + ') ORDER BY ' + @p_orden)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[lis_doc_subtipoDocumentos_m]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[lis_doc_subtipoDocumentos_m]
GO
CREATE PROCEDURE [lis_doc_subtipoDocumentos_m]
	@p_eid as varchar(50) = ''
AS
BEGIN
	SELECT id AS id,
[subtipoDocumento] AS [doc_subtipoDocumento]
	FROM [doc_subtipoDocumento]
	WHERE active = 1
	AND	(eid LIKE @p_eid+'%')
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[aud_doc_subtipoDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[aud_doc_subtipoDocumento]
GO
CREATE PROCEDURE [aud_doc_subtipoDocumento]
	@p_filtro as varchar (8000) = '1=1'
AS
BEGIN
exec(	'SELECT [doc_subtipoDocumento].id as id_tabla,
	[doc_subtipoDocumento].id_usuario_modifico as id_usuario_modifico,
	[doc_subtipoDocumento].id_usuario_creo as id_usuario_creo,
	[doc_subtipoDocumento].fechaModificacion as fechaModificacion,
	[doc_subtipoDocumento].fechaCreacion as fechaCreacion,
	[doc_subtipoDocumento].active as active,
	[doc_subtipoDocumento].[subtipoDocumento] as campoPrincipal,
	[seg_usuario_creo].usuario as usuarioCreo,
	[seg_usuario_modifico].usuario as usuarioModifico

	FROM [doc_subtipoDocumento]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[doc_subtipoDocumento].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[doc_subtipoDocumento].[id_usuario_creo]
	where ' + @p_filtro)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[sel_doc_estadoTipoDocumentosXsubtipoDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[sel_doc_estadoTipoDocumentosXsubtipoDocumento]
GO
CREATE PROCEDURE [sel_doc_estadoTipoDocumentosXsubtipoDocumento]
	@p_id_doc_subtipoDocumento INT
AS
BEGIN
	SELECT 	[doc_estadoTipoDocumento_subtipoDocumento].[id] AS [I_id],
		[doc_estadoTipoDocumento_subtipoDocumento].[uid] AS [I_uid],
		[doc_estadoTipoDocumento_subtipoDocumento].[eid] AS [I_eid],
		[doc_estadoTipoDocumento_subtipoDocumento].[fechaModificacion] AS [I_fechaModificacion],
		[doc_estadoTipoDocumento_subtipoDocumento].[fechaCreacion] AS [I_fechaCreacion],
		[doc_estadoTipoDocumento_subtipoDocumento].[active] AS [I_active],
		[doc_estadoTipoDocumento_subtipoDocumento].[estadoTipoDocumento_subtipoDocumento] AS [I_estadoTipoDocumento_subtipoDocumento]
	FROM doc_estadoTipoDocumento_subtipoDocumento INNER JOIN doc_estadoTipoDocumento
	 ON [doc_estadoTipoDocumento_subtipoDocumento].[id_estadoTipoDocumento] = [doc_estadoTipoDocumento].id
	WHERE	([doc_estadoTipoDocumento_subtipoDocumento].[id_subtipoDocumento]= @p_id_doc_subtipoDocumento)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[ins_doc_estadoTipoDocumento_subtipoDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[ins_doc_estadoTipoDocumento_subtipoDocumento]
GO
CREATE PROCEDURE [ins_doc_estadoTipoDocumento_subtipoDocumento]
	@p_uid varchar(500),
		@p_eid varchar(50),
		@p_id_usuario_modifico int,
		@p_id_usuario_creo int,
		@p_estadoTipoDocumento_subtipoDocumento varchar(300),
		@p_id_estadoTipoDocumento int,
		@p_id_subtipoDocumento int,
		@p_id_estadoTipoDocumento_destino int
AS
BEGIN
	DECLARE @v_id int
		INSERT INTO [doc_estadoTipoDocumento_subtipoDocumento]
			([uid],
			[eid],
			[id_usuario_modifico],
			[id_usuario_creo],
			[fechaModificacion],
			[fechaCreacion],
			[estadoTipoDocumento_subtipoDocumento],
			[id_estadoTipoDocumento],
			[id_subtipoDocumento],
			[id_estadoTipoDocumento_destino])
		VALUES(	@p_uid,
			@p_eid,
			@p_id_usuario_modifico,
			@p_id_usuario_creo,
			GETDATE(),
			GETDATE(),
			@p_estadoTipoDocumento_subtipoDocumento,
			@p_id_estadoTipoDocumento,
			@p_id_subtipoDocumento,
			@p_id_estadoTipoDocumento_destino)
		SET @v_id = scope_identity()
UPDATE [doc_estadoTipoDocumento_subtipoDocumento] set [uid] = [uid] + '_' + convert(varchar(20),@v_id) where [id]=@v_id
SELECT @v_id as id
RETURN @v_id
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[upd_doc_estadoTipoDocumento_subtipoDocumento]') AND type in (N'P', N'PC'))DROP PROCEDURE [dbo].[upd_doc_estadoTipoDocumento_subtipoDocumento]
GO
CREATE PROCEDURE [upd_doc_estadoTipoDocumento_subtipoDocumento]
	@p_id int = null,
		@p_uid varchar(500) = null,
		@p_eid varchar(50) = null,
		@p_id_usuario_modifico int = null,
		@p_id_usuario_creo int = null,
		@p_fechaCreacion smalldatetime = null,
		@p_estadoTipoDocumento_subtipoDocumento varchar(300) = null,
		@p_id_estadoTipoDocumento int = null,
		@p_id_subtipoDocumento int = null,
		@p_id_estadoTipoDocumento_destino int = null
AS
BEGIN
		UPDATE [doc_estadoTipoDocumento_subtipoDocumento]
		SET	[uid] = isnull(@p_uid,[uid]),
			[eid] = isnull(@p_eid,[eid]),
			[id_usuario_modifico] = isnull(@p_id_usuario_modifico,[id_usuario_modifico]),
			[id_usuario_creo] = isnull(@p_id_usuario_creo,[id_usuario_creo]),
			[fechaModificacion] = GETDATE(),
			[estadoTipoDocumento_subtipoDocumento] = isnull(@p_estadoTipoDocumento_subtipoDocumento,[estadoTipoDocumento_subtipoDocumento]),
			[id_estadoTipoDocumento] = isnull(@p_id_estadoTipoDocumento,[id_estadoTipoDocumento]),
			[id_subtipoDocumento] = isnull(@p_id_subtipoDocumento,[id_subtipoDocumento]),
			[id_estadoTipoDocumento_destino] = isnull(@p_id_estadoTipoDocumento_destino,[id_estadoTipoDocumento_destino])
		WHERE (id = @p_id)
END
GO
SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
----------------------
print 'doc_subtipoDocumento'
-----------------------------------02/04/2013 04:23:52 p.m.