
-- =============================================
-- Author:        Gcarlo
-- Create date: 
-- Description:    In base al database corrente passato ritorno il corretto linked Server AS400
-- =============================================
create FUNCTION f_getLikedAS400
(
    @CurrentDB nVarchar(128)   -- Database Corrente
)
RETURNS nvarchar(50)
AS
BEGIN
    -- Declare the return variable here
    DECLARE @As400File nvarchar(50);

    -- Valorizzo il corretto Linked Server in base al database passato
    SET @As400File = 
                  CASE
                    -- LINKED SERVER AS400 S.POSSIDONIO
                    WHEN ( LEFT(@CurrentDB,3) = 'SP_' ) THEN 'AS400POSS'   -- S.POSSIDONIO
                    -- LINKED SERVER AS400 TEKAL 
                    WHEN ( LEFT(@CurrentDB,3) = 'TK_' ) THEN 'AS400TEKAL'  -- TEKAL

                    ELSE ''
                   END

    -- Return the result of the function
    RETURN @As400File

END


