Options

Dynamic SQL

trevorlawrencetrevorlawrence Member Posts: 4
edited 2010-03-18 in SQL General
Hi All,

I wrote a store procedure with some parameters, based on that it fetch some data from database tables then generate a SQL Statment,

and i am executing this statment through EXECUTE IMMEDIATE.

The problem is that in database table I have one parameter with the name P_DIV.

i want to fetch the value of p_div in my parameter (the p_div is comming from db and the same in my store procedure)

but when the statment generated its take p_div rather then the value of p_div.

can u tell me how can i get the value rather then the variable.

Thanks,
Trevor.
debt

Comments

  • Options
    ara3nara3n Member Posts: 9,256
    I need a little more info.

    Could you put some example code on what your trying to do?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    strykstryk Member Posts: 645
    Have in mind that parameters should be declared like @p_div (beginning with an @); when using this in the code like:
    @tsql = 'SELECT ' + @p_div;
    
    NOT like this:
    @tsql = 'SELECT @p_div';
    -- or
    @tsql = 'SELECT p_div';
    
    Jörg A. Stryk (MVP - Dynamics NAV)
    NAV/SQL Performance Optimization & Troubleshooting
    STRYK System Improvement
    The Blog - The Book - The Tool
  • Options
    neshdenialneshdenial Member Posts: 3
    In this case, you will have to include and OUTPUT parameter & assign the error value to the variable and return it. You can find examples of using OUTPUT parameters with sp_ExecuteSQL in SQL Server Books Online...
Sign In or Register to comment.