CREATE PROCEDURE [BO_FilterCurrencies]
@AvailableKnoks BIT = null,
@ActiveKnoks BIT = null,
@EndedKnoks BIT = null,
@UserId bigint = null
AS

if @AvailableKnoks = 1

	SELECT  DISTINCT t.NonBase Code, t.NonBase CurrencyName, t.NonBase  LongName, 8 Decimals 
	from [Tickers] t  inner join [VW_PublicKnoks] k on k.TickerId = t.TickerId 
   
else if @ActiveKnoks = 1
	
	SELECT DISTINCT t.NonBase Code, t.NonBase CurrencyName, t.NonBase  LongName, 8 Decimals 
	from [Tickers] t  inner join [VW_ActiveKnoks] k on k.TickerId = t.TickerId 
    where (EXISTS (SELECT 1 FROM UserKnoks uk WHERE uk.UserId = @UserId AND uk.KnokId = k.KnokId))

else if @EndedKnoks = 1
	
	SELECT DISTINCT t.NonBase Code, t.NonBase CurrencyName, t.NonBase  LongName, 8 Decimals 
	from [Tickers] t  inner join [VW_EndedKnoks] k on k.TickerId = t.TickerId 
    where (EXISTS (SELECT 1 FROM UserKnoks uk WHERE uk.UserId = @UserId AND uk.KnokId = k.KnokId))

RETURN 0
