-- =============================================
-- Author:          <Author,,Name>
-- Create date: <Create Date,,>
-- Description:     <Description,,>
-- =============================================
-- dbo.GetVariableValue 's132_tempTestoAlt', 'N', null, 1
create PROCEDURE dbo.GetVariableValue 
       @VariableName nvarchar(128),
       @Flagnqp nvarchar(1) = null,
       @Flagprlrde nvarchar(1)  = null,
       @Flagpg int  = null
AS
BEGIN
       -- SET NOCOUNT ON added to prevent extra result sets from
       -- interfering with SELECT statements.
       SET NOCOUNT ON;
       select trv.variableValue from dbo.TextReplacementVariables trv
       where
             (@Flagnqp is null or @Flagnqp = trv.Flagnqp or trv.Flagnqp is null) and
             (@Flagprlrde is null or @Flagprlrde = trv.Flagprlrde or trv.Flagprlrde is null) and
             (@Flagpg is null or @Flagpg = trv.Flagpg or trv.Flagpg is null)
END