Changing Select Case used in Function to TSQL Query

  • Hi,

    I want to change the following function to a TSQL Query. Please help me in this regards.

    Public Function TranslatedVal(SecCashHedge as String, ReturnType as String, Local as Decimal, BaseUnhedged as Decimal, BaseHedged as Decimal) as Decimal

    Dim Val as Decimal

    Val = Local

    Select Case ReturnType

    Case "Local"

    Val = Local

    Case "Base"

    Val = Local

    Case "Base Unhedged"

    Val = BaseUnhedged

    Case "Base Hedged"

    Val = BaseHedged

    End Select

    Select Case SecCashHedge & ReturnType

    Case "AcctBase"

    Val = BaseHedged

    Case "AcctHedgingBase"

    Val = BaseHedged

    Case "AcctTranslationBase"

    Val = BaseHedged

    Case "IndexBase"

    Val = BaseHedged

    Case "IndexHedgingLocal"

    Val = 0

    Case "IndexHedgingBase"

    Val = BaseHedged

    Case "IndexHedgingBase Unhedged"

    Val = 0

    Case "IndexHedgingBase Hedged"

    Val = 0

    Case "IndexTranslationLocal"

    Val = 0

    Case "IndexTranslationBase"

    Val = BaseHedged

    Case "IndexTranslationBase Unhedged"

    Val = 0

    Case "IndexTranslationBase Hedged"

    Val = 0

    Case "AcctHedging & Translation Gains/LossesBase"

    Val = BaseHedged

    Case "IndexHedging & Translation Gains/LossesBase"

    Val = BaseHedged

    End Select

    Return Val

    End Function

    ______________________________________________________________________

    Ankit
    MCITP Database developer SQL 2008,MCTS Database Administration SQL 2008
    "Remembering that you are going to die is the best way I know to avoid the trap of thinking you have something to lose.
    You are already naked. There is no reason not to follow your heart.”

  • CASE (Transact-SQL)

    Need an answer? No, you need a question
    My blog at https://sqlkover.com.
    MCSE Business Intelligence - Microsoft Data Platform MVP

  • I don't know if it really applies to your code but we found turning some 'functions' that were just big case statements into a 'reference' table. This really sped up our queries.

    -------------------------------------------------------------
    we travel not to escape life but for life not to escape us
    Don't fear failure, fear regret.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply