SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[view_equ_campana]')) DROP VIEW [dbo].[view_equ_campana]
GO
CREATE  VIEW [view_equ_campana] AS
SELECT 	[equ_campana].[id] AS [id],
		[equ_campana].[uid] AS [uid],
		[equ_campana].[eid] AS [eid],
		[equ_campana].[id_usuario_modifico] AS [id_usuario_modifico],
		[equ_campana].[id_usuario_creo] AS [id_usuario_creo],
		[equ_campana].[fechaModificacion] AS [fechaModificacion],
		[equ_campana].[fechaCreacion] AS [fechaCreacion],
		[equ_campana].[active] AS [active],
		[equ_campana].[campana] AS [campana],
		[equ_campana].[campana_codigo] AS [campana_codigo],
		[equ_campana].[detalleCampana] AS [detalleCampana],
		[equ_campana].[fechaInicio_ff] AS [fechaInicio_ff],
		[equ_campana].[fechafin_ff] AS [fechafin_ff],
		[equ_campana].[activo] AS [activo],
		[equ_campana].[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],
		[equ_campana].[id_catalogo.tempario] AS [id_catalogo.tempario],
[cat_catalogo.tempario].[catalogo.tempario] as [cat_catalogo.tempario_catalogo.tempario],
[cat_catalogo.tempario].[duracionEstimada] as [cat_catalogo.tempario_duracionEstimada],
[cat_catalogo.tempario].[enTaller] as [cat_catalogo.tempario_enTaller],
[cat_catalogo.tempario].[esCiclico] as [cat_catalogo.tempario_esCiclico],
[cat_catalogo.tempario].[detieneEquipos] as [cat_catalogo.tempario_detieneEquipos],
[cat_catalogo.tempario].[horasDetencion] as [cat_catalogo.tempario_horasDetencion],
[cat_catalogo.tempario].[periodoHoras] as [cat_catalogo.tempario_periodoHoras],
[cat_catalogo.tempario].[facturaTodo] as [cat_catalogo.tempario_facturaTodo],
[cat_catalogo.tempario].[periodoDias] as [cat_catalogo.tempario_periodoDias],
[cat_catalogo.tempario].[porcGarantia] as [cat_catalogo.tempario_porcGarantia],
[cat_catalogo.tempario].[porcTropicalizacion] as [cat_catalogo.tempario_porcTropicalizacion],
[cat_catalogo.tempario].[id_tipoServicio] as [cat_catalogo.tempario_id_tipoServicio],
[cat_catalogo.tempario].[proyectar] as [cat_catalogo.tempario_proyectar],
[cat_catalogo.tempario].[incluirMenores] as [cat_catalogo.tempario_incluirMenores],
[cat_catalogo.tempario].[modoAjuste] as [cat_catalogo.tempario_modoAjuste],
		[cat_catalogo_tempario].[catalogo_codigo] AS [cat_catalogo_tempario_catalogo_codigo],
		[cat_catalogo_tempario].[codigoInventario] AS [cat_catalogo_tempario_codigoInventario],
		[cat_catalogo_tempario].[precioVenta] AS [cat_catalogo_tempario_precioVenta],
		[cat_catalogo_tempario].[tiempoConsecucion] AS [cat_catalogo_tempario_tiempoConsecucion],
		[cat_catalogo_tempario].[esNacional] AS [cat_catalogo_tempario_esNacional],
		[cat_catalogo_tempario].[id_familia] AS [cat_catalogo_tempario_id_familia],
		[cat_catalogo_tempario].[id_subtipoCatalogo] AS [cat_catalogo_tempario_id_subtipoCatalogo],
		[cat_catalogo_tempario].[id_unidad] AS [cat_catalogo_tempario_id_unidad],
		[cat_catalogo_tempario].[id_impuesto] AS [cat_catalogo_tempario_id_impuesto],
		[cat_catalogo_tempario].[descripcion] AS [cat_catalogo_tempario_descripcion],
		[cat_catalogo_tempario].[bloquearCostear] AS [cat_catalogo_tempario_bloquearCostear],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [equ_campana]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[equ_campana].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[equ_campana].[id_usuario_creo]
	INNER JOIN [ter_tercero] ON [ter_tercero].id=[equ_campana].[id_tercero]
	INNER JOIN [cat_catalogo.tempario] ON [cat_catalogo.tempario].id=[equ_campana].[id_catalogo.tempario]
	INNER JOIN [cat_catalogo] aS [cat_catalogo_tempario] ON [cat_catalogo.tempario].id = [cat_catalogo_tempario].id
	INNER JOIN [gen_empresa] AS empresaCodigo ON [equ_campana].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [equ_campana].active=1
