	IF OBJECT_ID('NET_SEL_VOO_TRECHO') IS NOT NULL
		DROP PROC NET_SEL_VOO_TRECHO

	GO
		CREATE PROC NET_SEL_VOO_TRECHO
	(
			  @pCodVooTrecho	int = NULL
			 ,@pCodVoo int = NULL
			 ,@pStatus INT = NULL
		    ,@pOrder VARCHAR(50) =  NULL 
	)
	AS 
		
		BEGIN
			SET NOCOUNT ON
			
					SELECT
					 CodVooTrecho
					,CodVoo
					,CodOrigem
					,case When CodOrigem >0 Then (SELECT Sigla FROM NET_AEROPORTO Where CodAeroporto= CodOrigem) Else '' End  As Origem
					,CodDestino
					,case When CodOrigem >0 Then (SELECT Sigla FROM NET_AEROPORTO Where CodAeroporto= CodDestino) Else '' End  As Destino
					,ds_cancel
					,Status
					,CodUsuario
					,DataCadastro

		FROM 
						NET_VOO_TRECHO
WHERE     
					((CodVooTrecho = @pCodVooTrecho) Or (@pCodVooTrecho IS NULL OR @pCodVooTrecho  = 0))
			And ((CodVoo  = @pCodVoo ) Or ((@pCodVoo  IS NULL OR @pCodVoo   = 0) And CodVoo  IS NULL))


			

	SET NOCOUNT OFF 
	END 

