Schema Modeler & Stored Procedures

I’m having great difficulty trying to use a stored procedure as a source for a custom table in schema modeler (version 8.1.87.1147 to be specific).

The only real piece of information I can gleam at the moment is via http://screencast.com/t/qwq4LD42mH which doesn’t really help me.

I have a stored procedure with a few integer parameters. It executes a CTE based SELECT to do some recursive hierarchical work, returning a table.

A simple worked example shown through Jing would be very much appreciated.

I’m at the point of giving up and writing a custom method on the server to do this, but would prefer to use a stored procedure (as I believe the functionality does / should exist). I’ve also tried just using the SQL of the stored procedure itself, but I don’t believe DA will support “WITH” and the CTE syntax. That is how I ended up trying to wrap it in a stored procedure.

Help greatly appreciated…

Paul.

Hello.
Sure we’ll try to help you.
But can you please describe in more details what your problem is? Can you show your stored procedure? What doesn’t work?

Statements with type SQL are going to server in the same way you are define it, and WITH and CTE statement are supported there.

Sorry that was a little vague Ekaterina - it was a last minute / late night post…

My basic problem is using a stored procedure in the schema as a source for a custom table. A simple worked example would be useful here as I can find virtually no documentation on how to achieve this - other than the screenshot linked in my first post. I found it very difficult to even get the schema modeler to allow me to select a stored procedure as the source for a table. I still don’t exactly know how I managed it as the drop down box listing stored procedures wasn’t available and then it was. Beyond that I still couldn’t progress much further as schema modeller didn’t appear to like using my stored procedure as the source, complaining about scalar variables being declared amongst other things. This despite the procedure working fine in SQL management studio etc… As you can see it is difficult to describe with any clarity as I have very little information from the documentation on how I should be doing it.

At that point I left it having previously tried to use the SQL directly as a source for a custom table in the schema. When doing that, DA was seeming managing to mangle the SQL so that when I looked in SQL profiler at the resulting call, there were extra square brackets inserted which fouled up the call.

As mentioned in the original post, I have now reverted to using a custom method on the server, with “AllowExecuteSQL” to enable the CTE SQL to execute correctly. On the client side I’m modifying the DataRequestCall on the remote data adapter. I do this for several other things and find it a good workaround to SQL issues.

I would still like to know how to correctly use a stored procedure as a source for a table though and if something like my original SQL should be capable of being the direct source for a custom table. I’ve listed my SQL below (which is effectively a bill of material implosion).I know is totally specific to me, but you will get an idea of the syntax I’m trying to use. Apologies for the layout, I need a tutorial on how to embed CR/LF when using preformatted text also (if that’s possible ?)

with UserCTE as (  select GIDComponent as GIDBase, NS.Model,NodeType,GIDParent,GIDComponent, DefComponent,NodeComponent, AH.TableName,AH.FieldName,Value, 0 as LevelNo  from NodeStructure NS join AggregationNodeHead AH on NS.Model = AH.Model and NS.DefComponent = AH.GID and AH.GIDSum = 0 join AggregationNodeDetail AD on NS.Model = AD.Model and NS.DefComponent = AD.GIDHead and NS.NodeComponent = AD.GID and AD.GIDSum = 0  union all  select Child.GIDBase, Parent.Model,Parent.NodeType,Parent.GIDParent,Parent.GIDComponent,Parent.DefComponent,Parent.NodeComponent, AH.TableName,AH.FieldName,AD.Value,Child.LevelNo +1 as LevelNo  FROM UserCTE AS Child     INNER JOIN NodeStructure AS Parent 
  on Child.Model= Parent.Model and Child.NodeType = Parent.NodeType and Child.GIDParent = Parent.GIDComponent   
  join AggregationNodeHead AH on Parent.Model = AH.Model and Parent.DefComponent = AH.GID and AH.GIDSum = 0
  join AggregationNodeDetail AD on Parent.Model = AD.Model and Parent.DefComponent = AD.GIDHead and Parent.NodeComponent = AD.GID and AD.GIDSum = 0) SELECT *   FROM UserCTE AS u where u.Model = 0 and u.NodeType = 0 and u.GIDBase = 36153  ORDER BY GIDBase, LevelNo desc

So to recap :

  1. Can you provide a simple screencast walkthrough showing of any stored procedure (with input parameters) being used as the source for a custom table.
  2. Should the above CTE query be compatible with supported DA syntax ?

Hello, Paul.
I tried to use MSSQL AdventureWorks2008 sample database, it contains stored procedures with CTE syntax. Please, check out the video: http://screencast.com/t/sokQYtLtrxnP

The easiest way to use stored procedure as source for the table - drag and drop it from connection manager. Schema table with all parameters will be generated automatically. Statement for it will be of ‘SQL’ type by default and contain sql for execution stored procedure with parameters: “EXEC [uspGetManagerEmployees] :BusinessEntityID”, you can see how it works on ‘Preview’ tab.
The other way is to select ‘StoredProcedure’ type of the statement on the SQL tab, then you can select the name of stored procedure, that you want to use as a source, in dropdown. And you are right this way has a bug, parameters for stored procedure didn’t recognised correctly. I’ve logged a bug #71688 and fixed it. Thanks for the report.
Here is documentation for Schema Modeler: http://wiki.remobjects.com/wiki/Schema_Modeler_for_Windows
Hope this helps.