Solved

COMMAND OBJECT - SET OUTPUT PARAMETER

Posted on 2002-07-11
5
201 Views
Last Modified: 2011-04-14
Hi experts,

I discovered the Data Environement Object, and I can't really get it to work my way.

First what I want it to get the Max Value of a field, and I was hoping to accomplish this with a single call to the command like:

MySort = MyDE.MyCommand (MyParent)

MyTable (table name) has the following fields:

MyId, MyName, MyParent, MySort

I would like to get the maximum value of the MySort field grouped by MyParent. I would like to do this all in the Data Environement (Command object) and not in the database directly. I will tell you what I did, and you please tell me where I went wrong ...

1. I created a Command Object and used a SQL-statement like:

SELECT MyTable.* FROM MyTable ORDER BY MyParent, MySort

Resulting Recordset:

MyId     MyName             Parent     Sort
0     MyGroups     0     0
6     Main1             0     1
7     Main2               0     2
1     Main3             0     4
5     Main4             0     5
2     Main5             0     6
3     Sub1             1     1
4     Sub2         1     2


2. I grouped it by MyParent.

3. I put the aggregate to Max (field: MySort)

Now the result is:

My parent / My Sort
0  /  6
1  /  2

4. In order to get a parameter I change the SQL to:

SELECT tblGroups.* FROM tblGroups WHERE GrpParent = ? ORDER BY GrpParent, GrpSort

Now the code looks like:

MyDE.ByParent (MyParent)

MyDE = Data Environement Object name
ByParent = Command objects - grouping name
MyParent = Variable that contains a parameter value


That's what I want. Then I thought I need only 1 value to be returned, not a recordset. I was thinking of adding a output parameter, and uncheck the "recordset returning" checkbox on the advanced tab of the command object properties.

How can I put an output parameter at design-time?
How can I access this value now? In code I mean.
How can I set the default value to "1" in case there are no records that match the criteria?
How can I add the value "1" to the returned value in the command object itself?

The command name is MyCommand.
The Grouping name is ByParent
The Aggregate name is MaxSort

I hope you understand.

Thanks ...

BL
0
Comment
Question by:beni_luedi
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 5

Expert Comment

by:rpai
ID: 7149976
To return only one record per MyParent, you can write a SQL statement like this:-
sSQL =  " SELECT Max(MySort), MyParent" & _
          " FROM tblGroups" & _
         " WHERE GrpParent = ? " & _
      " GROUP BY MyParent"

0
 

Author Comment

by:beni_luedi
ID: 7150927
How can I put an output parameter at design-time?
How can I access this value now? In code I mean.
How can I set the default value to "1" in case there are no records that match the criteria?
How can I add the value "1" to the returned value in the command object itself?
0
 
LVL 5

Expert Comment

by:rpai
ID: 7151486
Where do you want to put the output parameter?
Can you not use ADODB object model to accomplish your requirement?
0
 

Author Comment

by:beni_luedi
ID: 7151538
I want to put the output parameter together with the input parameter into the command object of the data environement designer (at design time).

Do you mean writing code to create a ADO command object with it's properties and parameters?

I would like to know if I can accoplish the same directly in the data environment's command object at design time.

Is this possible? If yes, HOW?
0
 
LVL 4

Accepted Solution

by:
AlonHirsch earned 100 total points
ID: 7153744
Hi,

Typically OUTPUT parameters are used when you call a stored procedure in SQL Server (ORACEL etc.).
The stored procedure uses Parameters for the query and has the option of returning data in one or more of the parameters.

You can't use output parameters with a direct SQL query as you are trying.

HTH,
Alon
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question