
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[view_doc_subtipoDocumento_atributo]')) DROP VIEW [dbo].[view_doc_subtipoDocumento_atributo]
GO
CREATE VIEW [dbo].[view_doc_subtipoDocumento_atributo] AS
SELECT 	[doc_subtipoDocumento_atributo].[id] AS [id],
		[doc_subtipoDocumento_atributo].[uid] AS [uid],
		[doc_subtipoDocumento_atributo].[eid] AS [eid],
		[doc_subtipoDocumento_atributo].[id_usuario_modifico] AS [id_usuario_modifico],
		[doc_subtipoDocumento_atributo].[id_usuario_creo] AS [id_usuario_creo],
		[doc_subtipoDocumento_atributo].[fechaModificacion] AS [fechaModificacion],
		[doc_subtipoDocumento_atributo].[fechaCreacion] AS [fechaCreacion],
		[doc_subtipoDocumento_atributo].[active] AS [active],
		[doc_subtipoDocumento_atributo].[subtipoDocumento_atributo] AS [subtipoDocumento_atributo],
		[doc_subtipoDocumento_atributo].[id_subtipoDocumento] AS [id_subtipoDocumento],
[doc_subtipoDocumento_atributo].[orden] AS [orden],
[doc_subtipoDocumento].[subtipoDocumento] as [doc_subtipoDocumento_subtipoDocumento],
[doc_subtipoDocumento].[subtipoDocumento_codigo] as [doc_subtipoDocumento_subtipoDocumento_codigo],
[doc_subtipoDocumento].[prefijo] as [doc_subtipoDocumento_prefijo],
[doc_subtipoDocumento].[consecutivo] as [doc_subtipoDocumento_consecutivo],
[doc_subtipoDocumento].[id_tipoDocumento] as [doc_subtipoDocumento_id_tipoDocumento],
		[doc_subtipoDocumento_atributo].[id_atributo] AS [id_atributo],
[cat_atributo].[atributo] as [cat_atributo_atributo],
[cat_atributo].[atributo_codigo] as [cat_atributo_atributo_codigo],
[cat_atributo].[esVariable] as [cat_atributo_esVariable],
[cat_atributo].[resaltado] as [cat_atributo_resaltado],
[cat_atributo].[valorMinimo] as [cat_atributo_valorMinimo],
[cat_atributo].[ValorMaximo] as [cat_atributo_ValorMaximo],
[cat_atributo].[id_seccionAtributo] as [cat_atributo_id_seccionAtributo],
[cat_atributo].[id_tipoAtributo] as [cat_atributo_id_tipoAtributo],
[cat_atributo].[id_unidad] as [cat_atributo_id_unidad],
[gen_unidad].unidad as unidad,
[cat_atributo].[nombreControl] as [cat_atributo_nombreControl],
[cat_atributo].[esObligatorio] as [cat_atributo_esObligatorio],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [doc_subtipoDocumento_atributo]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[doc_subtipoDocumento_atributo].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[doc_subtipoDocumento_atributo].[id_usuario_creo]
	INNER JOIN [doc_subtipoDocumento] ON [doc_subtipoDocumento].id=[doc_subtipoDocumento_atributo].[id_subtipoDocumento]
	INNER JOIN [cat_atributo] ON [cat_atributo].id=[doc_subtipoDocumento_atributo].[id_atributo]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [doc_subtipoDocumento_atributo].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
	INNER JOIN [gen_unidad] on  [gen_unidad].id=[cat_atributo].id_unidad
GO
