PC Review


Reply
Thread Tools Rate Thread

Cross-tab / pivot / transform a DataTable

 
 
David Jackson
Guest
Posts: n/a
 
      9th Jul 2009
Hello,

Firstly I apologise if this is the wrong newsgroup.

I am looking for a way to cross-tab / transform / pivot the data in a
DataTable fetched from a SQL Server stored procedure. Unfortunately, due to
company restrictions, I'm unable to modify the stored procedure or create a
different one.

The data is historical exchange rate data and, when fetched from SQL Server,
looks like this:

FxDate IsoCc FxRate
=====================
2009-07-01 AED 6.0533
2009-07-02 AED 6.0117
2009-07-03 AED 6.0029
2009-07-01 AUD 2.0401
2009-07-02 AUD 2.0578
2009-07-03 AUD 2.0442
2009-07-01 CAD 1.8921
2009-07-02 CAD 1.9004
2009-07-03 CAD 1.8950
....
....
....

The date range and currency range are chosen by the users at run-time.

Ideally, I would like to transform the above data so that it has the
following structure:

FxDate AED AUD CAD
============================
2009-07-01 6.0533 2.0401 1.8921
2009-07-02 6.0117 2.0578 1.9004
2009-07-03 6.0029 2.0442 1.8950

This transformed data will then be used as the datasource of a databound
control. There is no aggregation involved, simply a transformed arrangement
of the data.

A Google search reveals lots of examples of how to do this e.g.
http://redsouljaz.wordpress.com/2009...om-data-table/

But I'm wondering if this is really the only way to do this? Perhaps there
is a more efficient method available, maybe with LINQ?

N.B. I'm not expecting anyone to write my code for me, but I would be
grateful for any guidance with choosing the most efficient method.

Thank you.

DJ

 
Reply With Quote
 
 
 
 
Gregory A. Beamer
Guest
Posts: n/a
 
      9th Jul 2009
"David Jackson" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):

> Hello,
>
> Firstly I apologise if this is the wrong newsgroup.
>
> I am looking for a way to cross-tab / transform / pivot the data in a
> DataTable fetched from a SQL Server stored procedure. Unfortunately,
> due to company restrictions, I'm unable to modify the stored procedure
> or create a different one.
>
> SNIPPED CODE
>
> A Google search reveals lots of examples of how to do this e.g.
> http://redsouljaz.wordpress.com/2009...tab-pivot-from
> -data-table/
>
> But I'm wondering if this is really the only way to do this? Perhaps
> there is a more efficient method available, maybe with LINQ?
>
> N.B. I'm not expecting anyone to write my code for me, but I would be
> grateful for any guidance with choosing the most efficient method.



There are LINQ to SQL implementations you can find. The main methodology is
taking your result set and creating a new one by looping. MSDN has an
example where you hide this looping in extension methods, which is pretty
neat and makes it very easy to use LINQ. Stack Overflow has a few other
examples.

I am guessing you have to access the data via the stored procedure and
cannot simply write a new LINQ query to hit the data?


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

******************************************
| Think outside the box! |
******************************************
 
Reply With Quote
 
David Jackson
Guest
Posts: n/a
 
      9th Jul 2009
"Gregory A. Beamer" <(E-Mail Removed)> wrote in message
news:Xns9C434774A921Fgbworldcomcastnet@207.46.248.16...

Gregory,

> There are LINQ to SQL implementations you can find. The main methodology
> is
> taking your result set and creating a new one by looping. MSDN has an
> example where you hide this looping in extension methods, which is pretty
> neat and makes it very easy to use LINQ. Stack Overflow has a few other
> examples.


Thank you for this. I will investigate.

> I am guessing you have to access the data via the stored procedure and
> cannot simply write a new LINQ query to hit the data?


Unfortunately not. This is a temporary assignment and I'm not allowed to use
anything other than the existing stored procedures.

DJ

 
Reply With Quote
 
Gregory A. Beamer
Guest
Posts: n/a
 
      10th Jul 2009
"David Jackson" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):


> Unfortunately not. This is a temporary assignment and I'm not allowed
> to use anything other than the existing stored procedures.


Untrusting control freaks! ;-)

I understand fully. I have been on contract (and even a full time employee)
in a place with very strong security controls.


--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

******************************************
| Think outside the box! |
******************************************
 
Reply With Quote
 
David Jackson
Guest
Posts: n/a
 
      10th Jul 2009
"Gregory A. Beamer" <(E-Mail Removed)> wrote in message
news:Xns9C444BEE8CDA9gbworldcomcastnet@207.46.248.16...

>> Unfortunately not. This is a temporary assignment and I'm not allowed
>> to use anything other than the existing stored procedures.

>
> Untrusting control freaks! ;-)
>
> I understand fully. I have been on contract (and even a full time
> employee)
> in a place with very strong security controls.


Yes!

The SQL DBA / designer is a malodorous gentleman with a beard, John Lennon
glasses and a cardigan who enjoys several pints of Real Ale at lunchtime,
keeps popping outside to smoke his pipe, and just can't understand why the
company had to move away from OpenVMS on DEC VAX. I've never seen so many
stereotypes in one person before :-)

 
Reply With Quote
 
Gregory A. Beamer
Guest
Posts: n/a
 
      15th Jul 2009
"David Jackson" <(E-Mail Removed)> wrote in
news:(E-Mail Removed):


> The SQL DBA / designer is a malodorous gentleman with a beard, John
> Lennon glasses and a cardigan who enjoys several pints of Real Ale at
> lunchtime, keeps popping outside to smoke his pipe, and just can't
> understand why the company had to move away from OpenVMS on DEC VAX.
> I've never seen so many stereotypes in one person before :-)


I should have dropped the smiley on my comment then. ;-)

Sounds like you have the beatnik dinosaur complex working in the
organization. And, he probably thinks he is saving his job by being a
control freak. ;-)



--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Transform/PIVOT Query carl Microsoft Access Queries 4 27th Apr 2011 06:11 PM
Transform a Pivot chart into a report =?Utf-8?B?QWRyaWFuYQ==?= Microsoft Access Reports 0 24th Jun 2006 12:08 AM
Transform/pivot data (aka crosstabs) Manuel Microsoft ASP .NET 1 13th Oct 2005 04:26 PM
Pivot and Transform not working in SQL Server subir.kumar@citigroup.com Microsoft Access ADP SQL Server 2 25th May 2004 02:34 PM
Transform/Pivot SQL issue with form value Ron Microsoft Access Queries 0 7th Aug 2003 07:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:04 PM.