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.
Welcome to the forum! The SQL CASE expression is not used for such control-of-flow things. For that, you can use the commands mentioned here: http://msdn.microsoft.com/en-us/library/ms174290(v=sql.105).aspx Also, you can not SELECT a value from a column and execute it without using dynamic sql, but you might want to read more on this here: http://sommarskog.se/dynamic_sql.html Your whole requirement sounds strange and I would try a different implementation, if possible.