CREATE PROCEDURE [dbo].[fetch_countries] @region varchar(10) = ''
AS
BEGIN
	declare @select_query nvarchar(max) = '';

	SET @select_query = 'SELECT country_id,name FROM dim_country as country
				';

	IF  @region != '' and @region != 'na'
        BEGIN
            SET @select_query = @select_query + ' where region_id = ' + @region;
        END
	IF  @region = 'na'
        BEGIN
            SET @select_query = @select_query + ' where region_id IS NULL ' ;
        END
    SET @select_query = @select_query + ' order by name asc';
    EXEC sp_executesql  @select_query;
END;
go

