SET QUOTED_IDENTIFIER OFF 
GO
SET ANSI_NULLS ON
GO
IF  EXISTS (SELECT * FROM sys.views WHERE object_id = OBJECT_ID(N'[dbo].[view_ter_tercero]')) DROP VIEW [dbo].[view_ter_tercero]
GO
CREATE  VIEW [view_ter_tercero] AS
SELECT 	[ter_tercero].[id] AS [id],
		[ter_tercero].[uid] AS [uid],
		[ter_tercero].[eid] AS [eid],
		[ter_tercero].[id_usuario_modifico] AS [id_usuario_modifico],
		[ter_tercero].[id_usuario_creo] AS [id_usuario_creo],
		[ter_tercero].[fechaModificacion] AS [fechaModificacion],
		[ter_tercero].[fechaCreacion] AS [fechaCreacion],
		[ter_tercero].[active] AS [active],
		[ter_tercero].[tercero] AS [tercero],
		[ter_tercero].[tercero_codigo] AS [tercero_codigo],
		[ter_tercero].[tercero_nit] AS [tercero_nit],
		[ter_tercero].[direccion] AS [direccion],
		[ter_tercero].[contacto] AS [contacto],
		[ter_tercero].[telefono] AS [telefono],
		[ter_tercero].[fax] AS [fax],
		[ter_tercero].[email] AS [email],
		[ter_tercero].[website] AS [website],
		[ter_tercero].[representante] AS [representante],
		[ter_tercero].[notas] AS [notas],
		[ter_tercero].[tercero_nombreCorto] AS [tercero_nombreCorto],
		[ter_tercero].[esCliente] AS [esCliente],
		[ter_tercero].[esProveedor] AS [esProveedor],
		[ter_tercero].[esTransportador] AS [esTransportador],
		[ter_tercero].[esFabricante] AS [esFabricante],
		[ter_tercero].[esEmpresaPropia] AS [esEmpresaPropia],
		[ter_tercero].[clasificacion] AS [clasificacion],
		[ter_tercero].[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],
		[ter_tercero].[id_estadoTercero] AS [id_estadoTercero],
[ter_estadoTercero].[estadoTercero] as [ter_estadoTercero_estadoTercero],
[ter_estadoTercero].[estadoTercero_codigo] as [ter_estadoTercero_estadoTercero_codigo],
		[ter_tercero].[id_listaPrecio] AS [id_listaPrecio],
[cat_listaPrecio].[listaPrecio] as [cat_listaPrecio_listaPrecio],
[cat_listaPrecio].[listaPrecio_codigo] as [cat_listaPrecio_listaPrecio_codigo],
[cat_listaPrecio].[porcentajeDescuento] as [cat_listaPrecio_porcentajeDescuento],
		[ter_tercero].[id_naturalezaTercero] AS [id_naturalezaTercero],
[ter_naturalezaTercero].[naturalezaTercero] as [ter_naturalezaTercero_naturalezaTercero],
[ter_naturalezaTercero].[naturalezaTercero_codigo] as [ter_naturalezaTercero_naturalezaTercero_codigo],
		[ter_tercero].[esProspecto] AS [esProspecto],
		[empresaCodigo].[empresa] As [multiempresa]
FROM [ter_tercero]
	INNER JOIN [seg_usuario] AS [seg_usuario_modifico] ON [seg_usuario_modifico].id=[ter_tercero].[id_usuario_modifico]
	INNER JOIN [seg_usuario] AS [seg_usuario_creo] ON [seg_usuario_creo].id=[ter_tercero].[id_usuario_creo]
	INNER JOIN [gen_zona] ON [gen_zona].id=[ter_tercero].[id_zona]
	INNER JOIN [ter_estadoTercero] ON [ter_estadoTercero].id=[ter_tercero].[id_estadoTercero]
	INNER JOIN [cat_listaPrecio] ON [cat_listaPrecio].id=[ter_tercero].[id_listaPrecio]
	INNER JOIN [ter_naturalezaTercero] ON [ter_naturalezaTercero].id=[ter_tercero].[id_naturalezaTercero]
	INNER JOIN [gen_empresa] AS empresaCodigo ON [ter_tercero].eid = [empresaCodigo].[codigo] and empresaCodigo.active=1
WHERE [ter_tercero].active=1
GO
