Problem in query

  • I have a table which stores a Tax component and a formula pertaining to it as a string .

    I also have a function which returns the formula corresponding to the component

    Now i have to call this function in a query so that it automatically calculates the value.

    for eg: In my table i have a component 'Tot_HRA' and the respective formula HRA+ARRHRA

    My function dbo.returnformula('Tot_HRA') gives HRA+ARRHRA

    I also have two views where the values of HRA and ARRHRA is stored.

    if i write select dbo.returnformula('tot_hra') from the <two views>

    I get the formula only, instead i need the calculated value of HRA+ARRHRA

    I also tried select ' + dbo.returnformula('tot_hra') + ' etc

    What i need is like this

    select HRA+ARRHRA as Tot_HRA

    Why i need this is there are so many components for which i need the value which are based on some formula.  So instead of hardcoding the formula for each component if i have a dynamic way to get the values it will be very helpful.

    Thanks,

    Regards,

    K. Sripriya

     

     

     

  • You could declare a variable and set it to the result of the function....

    DECLARE @formula

    SELECT @formula = dbo.returnformula('tot_hra')

    EXEC ('SELECT ' + @formula + ' from <view1><view2> ' )

    Thanks!

    A

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

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