using ADO and SQL queries longer than 1024 char.

jjanauskas
Member Posts: 49
Hello,
Has anyone got an idea how to execute sql queries longer than 1024 characters using ADO in Navision.
The query I want to executed is generated dynamically during run-time, so stored procedures do not help here.
What I did: I output the generated sql to text file and then used special my written automation server (SQLFileExecuterX) which executes text files as sql queries...
But I thought, maybe somehow it is possible to do that without using SQLFileExecuterX, but using such features like BIGTEXT or Stream, or at least some standard software which goes together with navision/ado/windows...?
huh?
Has anyone got an idea how to execute sql queries longer than 1024 characters using ADO in Navision.
The query I want to executed is generated dynamically during run-time, so stored procedures do not help here.
What I did: I output the generated sql to text file and then used special my written automation server (SQLFileExecuterX) which executes text files as sql queries...
But I thought, maybe somehow it is possible to do that without using SQLFileExecuterX, but using such features like BIGTEXT or Stream, or at least some standard software which goes together with navision/ado/windows...?
huh?
0
Answers
-
I found another possible solution to the problem. You can use BSTRConverter automation server from NATHash.dll which comes together with Navision installation.
BSTRConverter is used to handle long text and has a method which returns BSTR type result. You can pass that result to ADO Recordset...ADORecset.Open(BSTRConverter.BSTR, ....
0 -
[Topic moved from Navision forum to SQL General forum]Regards,Alain Krikilion
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!0 -
None of the above solution work
xp_execresultset is removed from sql 2005
and ADORecordset.Open(NavHash.BSTR); errors withThe length of the text string exceeds the size of the string buffer.
Any other solution?0 -
Still no answer to a way to execute a sql statement that is longer than 1024?0
-
I think I've found a solution. I will post an update.0
-
Not really a solution. I had to change the sql statement to be shorter.
DECLARE @D Date Set @D = '10/07/10' (Select [Item No_],[Location Code],[Quantity], QtyToAdd = Case when ILE.[Positive] = 1 then (Select isnull(sum(IAE.[Quantity]),0) from [KRONUS$Item Application Entry] as IAE ,[KRONUS$Item Ledger Entry] as ILE2 where IAE.[Posting Date] >= @D and ILE2.[Posting Date] <= @D and IAE.[Outbound Item Entry No_] <> 0 and IAE.[Item Ledger Entry No_] = ILE2.[Entry No_] and ILE.[Entry No_] = IAE.[Inbound Item Entry No_]) else (Select isnull(sum(IAE.[Quantity]),0) from [KRONUS$Item Application Entry] as IAE,[KRONUS$Item Ledger Entry] as ILE2 where IAE.[Posting Date] >= @D and ILE2.[Posting Date] <= @D and IAE.[Item Ledger Entry No_] = ILE2.[Entry No_] and ILE.[Entry No_] = IAE.[Outbound Item Entry No_]) end, (Select isnull(sum(VEntry.[Cost Amount (Expected)]+ VEntry.[Cost Amount (Actual)]),0) from [KRONUS$Value Entry] as VEntry where VEntry.[Posting Date] <= @D and VEntry.[Item Ledger Entry No_] = ILE.[Entry No_]) as [Inventory Value] from [KRONUS$Item Ledger Entry] AS ILE where ILE.[Posting Date] <= @D)
Changed toDECLARE @D Date Set @D = '10/07/10' (Select [Item No_],[Location Code],[Quantity], QtyToAdd = (Select isnull(sum(IAE.[Quantity]),0) from [KRONUS$Item Application Entry] as IAE ,[KRONUS$Item Ledger Entry] as ILE2 where IAE.[Posting Date] >= @D and ILE2.[Posting Date] <= @D and IAE.[Outbound Item Entry No_] <> 0 and IAE.[Item Ledger Entry No_] = ILE2.[Entry No_] and ((ILE.[Positive] = 1 and ILE.[Entry No_] = IAE.[Inbound Item Entry No_]) OR (ILE.[Positive] = 0 and ILE.[Entry No_] = IAE.[Outbound Item Entry No_]))), (Select isnull(sum(VEntry.[Cost Amount (Expected)]+ VEntry.[Cost Amount (Actual)]),0) from [KRONUS$Value Entry] as VEntry where VEntry.[Posting Date] <= @D and VEntry.[Item Ledger Entry No_] = ILE.[Entry No_]) as [Inventory Value] from [KRONUS$Item Ledger Entry] AS ILE where ILE.[Posting Date] <= @D)
0 -
It's not that difficult to solve this problem, just use the VBScript OCX or DLL.
I'm using this technique to automatically generate some rather large trigger code, about 128K in 3000 lines for example.VBScript Automation 'Microsoft Script Control 1.0'.ScriptControl or .. VBScript OCX ScriptControl Object VBScript.Language('VBScript'); Session.SETRANGE("My Session", TRUE); Session.FIND('-'); VBScript.AddCode('set SQL = CreateObject("ADODB.Connection")'); VBScript.AddCode('SQL.open("Provider=sqloledb;Data Source=(local);Initial Catalog=' + Session."Database Name" + ';Integrated Security=SSPI")'); VBScript.AddCode('StrData = ""'); VBScript.AddCode('Sub AddLine(str) : StrData = StrData & str & vbCRLF : End Sub'); VBScript.AddCode('Sub RunSQL : SQL.Execute(strData) : StrData = "" : End Sub'); VBScript.ExecuteStatement('AddLine("' + 'drop table zxyzzy' + '")'); VBScript.ExecuteStatement('RunSQL');
You probably want to use BSTRConverter to build the string to avoid the horrible quoting issues.VBBS Automation 'Navision Attain Hash 1.0'.BSTRConverter VBScript.AddObject('BS', VBBS, FALSE); VBBS.BSTR := LineData; VBBS.AppendNextStringPortion(LineData2); VBScript.ExecuteStatement('StrData = StrData & BS.BSTR & vbCRLF');
BTW: for the record, VBScript does seem to be the answer to any little problems you may have with Navision ...Robert de Bath
TVision Technology Ltd0 -
You can use xmlTextNode objects to pass long SQL queries into ado objects.
xmlTextNode.appendData(query1);
xmlTextNode.appendData(query2);
xmlTextNode.appendData(query3);
xmlTextNode.appendData(query4);
xmlTextNode.appendData(query5);
xmlTextNode.appendData(query6);
xmlTextNode.appendData(query7);
adoRs.Open(xmlTextNode.nodeValue, adoConn);Looking for part-time work.
Nav, T-SQL.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