

IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[view_dis_obra]')) DROP VIEW [dbo].[view_dis_obra]
GO
CREATE  VIEW [view_dis_obra] AS
SELECT 	[dis_obra].[id] AS [id],
		[dis_obra].[uid] AS [uid],
		[dis_obra].[eid] AS [eid],
		[dis_obra].[id_usuario_modifico] AS [id_usuario_modifico],
		[dis_obra].[id_usuario_creo] AS [id_usuario_creo],
		[dis_obra].[fechaModificacion] AS [fechaModificacion],
		[dis_obra].[fechaCreacion] AS [fechaCreacion],
		[dis_obra].[active] AS [active],
		[dis_obra].[obra] AS [obra],
		[dis_obra].[obra_codigo] AS [obra_codigo],
		[dis_obra].[fechaInicial_ff] AS [fechaInicial_ff],
		[dis_obra].[fechaFinal_ff] AS [fechaFinal_ff],
		[dis_obra].[id_sucursal] AS [id_sucursal],
[ter_sucursal].[sucursal] as [ter_sucursal_sucursal],
[ter_sucursal].[sucursal_codigo] as [ter_sucursal_sucursal_codigo],
[ter_sucursal].[contacto] as [ter_sucursal_contacto],
[ter_sucursal].[telefono] as [ter_sucursal_telefono],
[ter_sucursal].[Fax] as [ter_sucursal_Fax],
[ter_sucursal].[Email] as [ter_sucursal_Email],
[ter_sucursal].[Direccion] as [ter_sucursal_Direccion],
[ter_sucursal].[paraVenta] as [ter_sucursal_paraVenta],
[ter_sucursal].[paraSoporte] as [ter_sucursal_paraSoporte],
[ter_sucursal].[paraAlquiler] as [ter_sucursal_paraAlquiler],
[ter_sucursal].[id_tercero] as [ter_sucursal_id_tercero],
[ter_sucursal].[id_zona] as [ter_sucursal_id_zona],
[ter_sucursal].[id_usuario_asesor] as [ter_sucursal_id_usuario_asesor],
[ter_sucursal].[id_usuario_tecnico] as [ter_sucursal_id_usuario_tecnico],
[ter_sucursal].[id_sucursal] as [ter_sucursal_id_sucursal],
[ter_sucursal].[id_listaPrecio] as [ter_sucursal_id_listaPrecio],
[ter_sucursal].[id_estadoTercero] as [ter_sucursal_id_estadoTercero],
[ter_sucursal].[codigorecursiva] as [ter_sucursal_codigorecursiva],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [dis_obra]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[dis_obra].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[dis_obra].[id_usuario_creo]
	INNER JOIN [ter_sucursal] ON [ter_sucursal].id=[dis_obra].[id_sucursal]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [dis_obra].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [dis_obra].active=1
