IF OBJECT_ID('NET_SEL_PARTEVENTTRECHO') IS NOT NULL
	DROP PROC NET_SEL_PARTEVENTTRECHO
/*****************************************************
Author:	Fabio Eduardo
Date:      11/08/2008
Purpose: Seleciona trechos de um evneto no qual o participante 
				Esta associado

*****************************************************/
GO
CREATE PROC NET_SEL_PARTEVENTTRECHO
(
	 @PCodEvento  INT =  NULL
	 ,@PCodParticipante	 INT =  NULL
	
)AS
DECLARE @MsgErr VARCHAR(100)
  	  BEGIN

SELECT 
				CodVoo
			   ,CodVooTrecho
			   ,CodOrigem
			    ,Case When  CodOrigem > 0 Then (SELECT TOP 1 Sigla FROM NET_AEROPORTO  Where CodAeroporto=CodOrigem ) Else '' End As Origem  
			   ,CodDestino
				,Case When  CodDestino > 0 Then (SELECT TOP 1 Sigla FROM NET_AEROPORTO  Where CodAeroporto=CodDestino ) Else '' End As Destino
				,Case When Exists(SELECT TOP 1 CodParticipante  FROM  NET_PARTICIPANTE_VOO Where CodParticipante = @PCodParticipante And CodVooTrecho = NET_VOO_TRECHO.CodVooTrecho) Then 'Checked' Else '' End As Checked
FROM 
				NET_VOO_TRECHO 
	WHERE 
				 CodVooTrecho IN (
	SELECT 
				 CodVooTrecho
	FROM 
					NET_EVENTO_VOO
Where CodEvento = @PCodEvento

)


		END


