?
Solved

Changing data type between Provider and Clientdataset

Posted on 2013-01-31
6
Medium Priority
?
765 Views
Last Modified: 2013-02-01
I have a stored procedure (sp_who2) that is returning a varchar containing a number (CPUTime).  I am pulling the dataset into a ClientDataSet for use in my program, but would like the column to be an integer so that indexing on it will be in the correct order.  

How can I best do that?
0
Comment
Question by:GNiessen
[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
  • 2
6 Comments
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 38841414
you mean sorting, not indexing ?
0
 
LVL 27

Expert Comment

by:Sinisa Vuk
ID: 38841587
You can do this on server side by casting filed:

select cast(CPUTime as int) as CPUTime, Field2, Field3 from table1....

Open in new window

0
 

Author Comment

by:GNiessen
ID: 38841714
#Geert  The ClientDataSet has Indexes for sorting.

#sinesav  You can't select from a stored procedure.  If it were a view or a table it would be easy.  And as this is a system stored procedure I can't modify it to run the way I want.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 38842724
you could  (or ask to) add a sql zone to your Q with request attention

have you tried with a wrapper procedure ?
create a procedure which puts the output of the system proc in a temp table,
then run your select from that temp table

it's been over a decade since i did mssql but here goes ...
http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/61dfc83d-65a7-4df0-9410-400e70b77f9c/

if you put a select statement last in your proc it will behave as a query in delphi
0
 
LVL 27

Accepted Solution

by:
Sinisa Vuk earned 750 total points
ID: 38842955
I missed "stored procedure". You cannot change field type on the fly because it allocate memory as string. But...

1. add all field defs + one additional 'ID' field defined as Integer and must be InternalCalc of kind.

http://edn.embarcadero.com/article/28959

2. Add procedure SortCustomClientDataSet from page: http://edn.embarcadero.com/article/29056 ... and add following code with new OnCalcField event on dataset (where you convert string to integer on the fly):

procedure TForm1.Button1Click(Sender: TObject);
begin
  ClientDataSet1.Close;
  ClientDataSet1.Open;
  SortCustomClientDataSet(ClientDataSet1, 'ID');
end;

procedure TForm1.ClientDataSet1CalcFields(DataSet: TDataSet);
begin
  ClientDataSet1.FieldByName('ID').AsInteger :=
    StrToIntDef(ClientDataSet1.FieldByName('CPUTime').AsString, 0);
end;

Open in new window

0
 

Author Closing Comment

by:GNiessen
ID: 38843325
Setting up the an internal calc field worked and I was able to index on it.  I had hoped there was a way to control more the data transformation between the stored procedure and the Clientdataset, but it is working good enough for this purpose.

Thanks all.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

752 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