Create a variable cursor

Magno
Member Posts: 168
Hi,
I want to create a cursor dynamically to a non determined company\table in NAV.
like this:
Is this possible to do?
I want to create a cursor dynamically to a non determined company\table in NAV.
like this:
DECLARE @Company varchar( 50); DECLARE @Table varchar( 50); DECLARE @EndPoint int; SET @Company = 'Company'; SET @Table = 'TableName'; DECLARE curData CURSOR LOCAL FAST_FORWARD FOR Select DISTINCT EndPoint from [@Company$@TableName] OPEN curData FETCH NEXT FROM curData INTO @EndPoint WHILE @@FETCH_STATUS = 0 BEGIN print @EndPoint -- GET NEXT FETCH NEXT FROM curData INTO @EndPoint END CLOSE curData DEALLOCATE curData
Is this possible to do?
0
Answers
-
that is not really an option (recordRef and fieldRef), i know these, because the SQL Statements i'm making are as a replacement for the field and recordRef. The Ref's take too long for what we want to do.
I have the prototype code in SQL, but specific for 1 company now and need to built it into a stored procedure.0 -
So and whats there your question and why do you need it direktcly from NAV
Per default NAV can't run direkt TSQL. Only via ADO or if you use a View and in this view is TSQL (for example the view call a function)Do you make it right, it works too!0 -
Who said anything about running this from navision.
I run this in SSMS (SQL Server Management Studio) just because i can use the speed of SQL Server in my process then. My goal is to create a stored procedure to call in Navision using ADO.0 -
Magno wrote:Who said anything about running this from navision.
Because you post it in the NAV/Navision subforum.My goal is to create a stored procedure to call in Navision using ADO.
OK, also no problem. For ADO here are many examples, and how to create and save a sp under the Management Studio also simple. How to run a sp from NAv with using ADO is also no prob and you found it also if you search the forum.
Is your final question how to display the resultset of the sp in NAV, for example in a form?Do you make it right, it works too!0 -
no, my question was if there is another way to create a dynamic cursor, i was wondering if other people have done this in NAV.
The sp and ADO part i have done before.0 -
One of the changes in NAV 5, was to change from primarily making use of Fast-Forward cursor types to Dynamic cursors. The same change was implemented in version 4 from build 26410, which is Version 4, SP3 Update6(940718) + KB950920.
Before 5 / 4.03 Update 6 NAv use ever the FF courser type.
http://blogs.msdn.com/microsoft_dynamic ... types.aspxDo you make it right, it works too!0 -
[Topic moved from 'NAV/Navision' forum to 'SQL General' forum]Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
I guess you are looking for something like this:
set statistics io off declare @cust_name varchar(30) declare @tab_name varchar(128) set @tab_name = 'CRONUS 403$Customer' exec ('declare dyn_cur cursor for select [Name] from [' + @tab_name + ']') open dyn_cur fetch next from dyn_cur into @cust_name while @@fetch_status = 0 begin print @cust_name fetch next from dyn_cur into @cust_name end close dyn_cur deallocate dyn_cur
Hence, the "EXEC" of the dynamic SQL does the trick ...Jörg A. Stryk (MVP - Dynamics NAV)
NAV/SQL Performance Optimization & Troubleshooting
STRYK System Improvement
The Blog - The Book - The Tool0 -
stryk wrote:I guess you are looking for something like this:
set statistics io off declare @cust_name varchar(30) declare @tab_name varchar(128) set @tab_name = 'CRONUS 403$Customer' exec ('declare dyn_cur cursor for select [Name] from [' + @tab_name + ']') open dyn_cur fetch next from dyn_cur into @cust_name while @@fetch_status = 0 begin print @cust_name fetch next from dyn_cur into @cust_name end close dyn_cur deallocate dyn_cur
Hence, the "EXEC" of the dynamic SQL does the trick ...
Great, this is indeed what i wanted. I looked into the exec, but didn't know the cursor would be known outside the exec as well.
Thx!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