SQL Server Performance

EXEC statement inside case statement

Discussion in 'ALL SQL SERVER QUESTIONS' started by jmathewp, May 13, 2012.

  1. jmathewp New Member

    I have a table TAB1 with the below structure
    Index Function (This column contains the full function stored as string)
    AAA Null
    BBB fn_evaluate1()
    CCC fn_evaluate2()
    DDD Null

    My requirement :-
    1. When Function = null – Fetch rate for this Index from another table TAB2
    2. If not null execute the function stored in the Function column of TAB1 and get the calculated value as rate.
    I tried this –
    SELECT A.Index,
    CASE WHEN (A.Functions IS NULL)
    THEN B.Rate
    ELSE
    Exec A.Function-- Need to execute the Function stored as string in the function column of TAB1
    END Rate
    FROM TAB1 A LEFT JOIN TAB2 B
    on A.Index=B.Index

    I could not execute the statement since it is giving a syntax error near exec.
  2. FrankKalis Moderator

Share This Page