SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[view_lic_licencia]')) DROP VIEW [dbo].[view_lic_licencia]
GO
CREATE  VIEW [view_lic_licencia] AS
SELECT 	[lic_licencia].[id] AS [id],
		[lic_licencia].[uid] AS [uid],
		[lic_licencia].[eid] AS [eid],
		[lic_licencia].[id_usuario_modifico] AS [id_usuario_modifico],
		[lic_licencia].[id_usuario_creo] AS [id_usuario_creo],
		[lic_licencia].[fechaModificacion] AS [fechaModificacion],
		[lic_licencia].[fechaCreacion] AS [fechaCreacion],
		[lic_licencia].[active] AS [active],
		[lic_licencia].[licencia] AS [licencia],
		[lic_licencia].[licencia_codigo] AS [licencia_codigo],
		[lic_licencia].[serial] AS [serial],
		[lic_licencia].[clave] AS [clave],
		[lic_licencia].[fechaInicio_ff] AS [fechaInicio_ff],
		[lic_licencia].[fechaFin_ff] AS [fechaFin_ff],
		[lic_licencia].[id_tercero] AS [id_tercero],
[ter_tercero].[tercero] as [ter_tercero_tercero],
[ter_tercero].[tercero_codigo] as [ter_tercero_tercero_codigo],
[ter_tercero].[tercero_nit] as [ter_tercero_tercero_nit],
[ter_tercero].[direccion] as [ter_tercero_direccion],
[ter_tercero].[contacto] as [ter_tercero_contacto],
[ter_tercero].[telefono] as [ter_tercero_telefono],
[ter_tercero].[fax] as [ter_tercero_fax],
[ter_tercero].[email] as [ter_tercero_email],
[ter_tercero].[website] as [ter_tercero_website],
[ter_tercero].[representante] as [ter_tercero_representante],
[ter_tercero].[notas] as [ter_tercero_notas],
[ter_tercero].[tercero_nombreCorto] as [ter_tercero_tercero_nombreCorto],
[ter_tercero].[esCliente] as [ter_tercero_esCliente],
[ter_tercero].[esProveedor] as [ter_tercero_esProveedor],
[ter_tercero].[esTransportador] as [ter_tercero_esTransportador],
[ter_tercero].[esFabricante] as [ter_tercero_esFabricante],
[ter_tercero].[esEmpresaPropia] as [ter_tercero_esEmpresaPropia],
[ter_tercero].[clasificacion] as [ter_tercero_clasificacion],
[ter_tercero].[id_zona] as [ter_tercero_id_zona],
[ter_tercero].[id_estadoTercero] as [ter_tercero_id_estadoTercero],
[ter_tercero].[id_listaPrecio] as [ter_tercero_id_listaPrecio],
[ter_tercero].[id_naturalezaTercero] as [ter_tercero_id_naturalezaTercero],
[ter_tercero].[esProspecto] as [ter_tercero_esProspecto],
		[lic_licencia].[id_catalogo] AS [id_catalogo],
[cat_catalogo].[catalogo] as [cat_catalogo_catalogo],
[cat_catalogo].[catalogo_codigo] as [cat_catalogo_catalogo_codigo],
[cat_catalogo].[codigoInventario] as [cat_catalogo_codigoInventario],
[cat_catalogo].[precioVenta] as [cat_catalogo_precioVenta],
[cat_catalogo].[tiempoConsecucion] as [cat_catalogo_tiempoConsecucion],
[cat_catalogo].[esNacional] as [cat_catalogo_esNacional],
[cat_catalogo].[id_familia] as [cat_catalogo_id_familia],
[cat_catalogo].[id_subtipoCatalogo] as [cat_catalogo_id_subtipoCatalogo],
[cat_catalogo].[id_unidad] as [cat_catalogo_id_unidad],
[cat_catalogo].[id_impuesto] as [cat_catalogo_id_impuesto],
[cat_catalogo].[descripcion] as [cat_catalogo_descripcion],
[cat_catalogo].[bloquearCostear] as [cat_catalogo_bloquearCostear],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [lic_licencia]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[lic_licencia].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[lic_licencia].[id_usuario_creo]
	INNER JOIN [ter_tercero] ON [ter_tercero].id=[lic_licencia].[id_tercero]
	INNER JOIN [cat_catalogo] ON [cat_catalogo].id=[lic_licencia].[id_catalogo]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [lic_licencia].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [lic_licencia].active=1
