SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[view_cnt_contrato_zona]')) DROP VIEW [dbo].[view_cnt_contrato_zona]
GO
CREATE  VIEW [view_cnt_contrato_zona] AS
SELECT 	[cnt_contrato_zona].[id] AS [id],
		[cnt_contrato_zona].[uid] AS [uid],
		[cnt_contrato_zona].[eid] AS [eid],
		[cnt_contrato_zona].[id_usuario_modifico] AS [id_usuario_modifico],
		[cnt_contrato_zona].[id_usuario_creo] AS [id_usuario_creo],
		[cnt_contrato_zona].[fechaModificacion] AS [fechaModificacion],
		[cnt_contrato_zona].[fechaCreacion] AS [fechaCreacion],
		[cnt_contrato_zona].[active] AS [active],
		[cnt_contrato_zona].[contrato_zona] AS [contrato_zona],
		[cnt_contrato_zona].[precioVisita] AS [precioVisita],
		[cnt_contrato_zona].[precioServicio] AS [precioServicio],
		[cnt_contrato_zona].[id_contrato] AS [id_contrato],
[cnt_contrato].[contrato] as [cnt_contrato_contrato],
[cnt_contrato].[contrato_codigo] as [cnt_contrato_contrato_codigo],
[cnt_contrato].[numero] as [cnt_contrato_numero],
[cnt_contrato].[totalContrato] as [cnt_contrato_totalContrato],
[cnt_contrato].[presupuesto] as [cnt_contrato_presupuesto],
[cnt_contrato].[fechaInicio_ff] as [cnt_contrato_fechaInicio_ff],
[cnt_contrato].[fechaFin_ff] as [cnt_contrato_fechaFin_ff],
[cnt_contrato].[diasCumplimiento] as [cnt_contrato_diasCumplimiento],
[cnt_contrato].[condiciones] as [cnt_contrato_condiciones],
[cnt_contrato].[id_periodoContrato] as [cnt_contrato_id_periodoContrato],
[cnt_contrato].[id_tercero] as [cnt_contrato_id_tercero],
[cnt_contrato].[id_tipoServicio] as [cnt_contrato_id_tipoServicio],
[cnt_contrato].[id_tipoContrato] as [cnt_contrato_id_tipoContrato],
[cnt_contrato].[id_tercero_servicio] as [cnt_contrato_id_tercero_servicio],
[cnt_contrato].[id_subtipoDocumento] as [cnt_contrato_id_subtipoDocumento],
[cnt_contrato].[id_departamentoSolicitud] as [cnt_contrato_id_departamentoSolicitud],
[cnt_contrato].[id_usuario_coordinador] as [cnt_contrato_id_usuario_coordinador],
		[cnt_contrato_zona].[id_zona] AS [id_zona],
[gen_zona].[zona] as [gen_zona_zona],
[gen_zona].[zona_codigo] as [gen_zona_zona_codigo],
[gen_zona].[tiempoDesplazamiento] as [gen_zona_tiempoDesplazamiento],
[gen_zona].[nivel] as [gen_zona_nivel],
[gen_zona].[id_zona] as [gen_zona_id_zona],
[gen_zona].[codigoExterno] as [gen_zona_codigoExterno],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [cnt_contrato_zona]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[cnt_contrato_zona].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[cnt_contrato_zona].[id_usuario_creo]
	INNER JOIN [cnt_contrato] ON [cnt_contrato].id=[cnt_contrato_zona].[id_contrato]
	INNER JOIN [gen_zona] ON [gen_zona].id=[cnt_contrato_zona].[id_zona]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [cnt_contrato_zona].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
GO
