Dynamic SQL

trevorlawrence
Member Posts: 4
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.
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
0
Comments
-
I need a little more info.
Could you put some example code on what your trying to do?0 -
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 Tool0 -
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...0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions