ALTER  VIEW [dbo].[view_cnt_contratoDetalleVisita] AS
SELECT 	[cnt_contratoDetalleVisita].[id] AS [id],
		[cnt_contratoDetalleVisita].[uid] AS [uid],
		[cnt_contratoDetalleVisita].[eid] AS [eid],
		[cnt_contratoDetalleVisita].[id_usuario_modifico] AS [id_usuario_modifico],
		[cnt_contratoDetalleVisita].[id_usuario_creo] AS [id_usuario_creo],
		[cnt_contratoDetalleVisita].[fechaModificacion] AS [fechaModificacion],
		[cnt_contratoDetalleVisita].[fechaCreacion] AS [fechaCreacion],
		[cnt_contratoDetalleVisita].[active] AS [active],
		[cnt_contratoDetalleVisita].[contratoDetalleVisita] AS [contratoDetalleVisita],
		[cnt_contratoDetalleVisita].[contratoDetalleVisita_codigo] AS [contratoDetalleVisita_codigo],
		[cnt_contratoDetalleVisita].[frecuencia] AS [frecuencia],
		[cnt_contratoDetalleVisita].[cadaN] AS [cadaN],
		[cnt_contratoDetalleVisita].[dia] AS [dia],
		[cnt_contratoDetalleVisita].[estrategia] AS [estrategia],
		[cnt_contratoDetalleVisita].[porTrabajo] AS [porTrabajo],
		[cnt_contratoDetalleVisita].[incluirMenores] AS [incluirMenores],
		[cnt_contratoDetalleVisita].[aproximarA] AS [aproximarA],
		[cnt_contratoDetalleVisita].[fecha_ff] AS [fecha_ff],
		[cnt_contratoDetalleVisita].[id_contrato] AS [id_contrato],
		[cnt_contratoDetalleVisita].[fechaInactivaInicial_ff] AS [fechaInactivaInicial_ff],
		[cnt_contratoDetalleVisita].[fechaInactivaFinal_ff] AS [fechaInactivaFinal_ff],
[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_contratoDetalleVisita].[diaHabil] AS [diaHabil],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [cnt_contratoDetalleVisita]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[cnt_contratoDetalleVisita].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[cnt_contratoDetalleVisita].[id_usuario_creo]
	INNER JOIN [cnt_contrato] ON [cnt_contrato].id=[cnt_contratoDetalleVisita].[id_contrato]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [cnt_contratoDetalleVisita].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [cnt_contratoDetalleVisita].active=1
