When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML Info
Information:
Advertise
Feedback
Author an Article
Technology Jobs

















internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.

Windows Systems Administrator
Jupitermedia
US-CT-Darien

Justtechjobs.com Post A Job | Post A Resume

Published: Saturday, September 25, 1999

Data Shaping, Part 2


We've examined how to retrieve the Class and Professor tables using JOINs. While there is nothing wrong with using JOINs, some folks find the syntax tricky. Also, the data received needs some formatting. In Part 1, when we listed the professors and the classes they taught, a professor's name was listed as many times as the number of classes he or she taught! It would be nice to have the output formatted like:

Dr. Mitchell
    Formal Languages & Automata Theory
    Study of Film
    Software Engineering
While this can be done using a little ASP logic, it is a bit nasty.

- continued -

Data shaping is a new feature of ADO 2.0. It allows us to grab data from a database, and puts the related data in a recordset. So, in our example, we could bring back a simple recordset of professors, which could contain their FirstName, LastName, PhoneNumber, and classes taught. The classes taught field would be a recordset itself, containing all of the class information! This may seem a bit mind blowing, since we are retrieving recordets containing recordsets! This is why data shaping is so cool, though!

We have to use a special syntax for data shaping.

SHAPE {parent SQL statement} [[AS] alias]
APPEND({child SQL statement} [[AS] alias]
RELATE parent column TO child column) [[AS] alias]

The parent SQL statement and the child SQL statement are both just simple SQL statements. If we wanted to obtain a list of professors and classes they taught, the SQL statement to retrieve the list of professors would be the parent SQL statement, while the SQL statement to retrieve the list of classes would be the child SQL statement. The two statements would be related on ProfessorID. Therefore, the syntax for our data shape would look like:

SHAPE {SELECT ProfessorID, FirstName, LastName, PhoneNumber FROM Professor}
APPEND({SELECT ClassName, RefNumber, ProfessorID FROM Class} AS Class
RELATE ProfessorID TO ProfessorID)

What if we wanted to obtain a listing of the classes and the professors that taught them? Well, we'd simply reverse the parent and child SQL statements. The syntax would change to:

SHAPE {SELECT ClassName, RefNumber, ProfessorID FROM Class}
APPEND({SELECT ProfessorID, FirstName, LastName, PhoneNumber FROM Professor} AS Prof
RELATE ProfessorID TO ProfessorID)

It is important that the column you are relating appear both in the parent and child SQL statements. If you leave out the relating column from either SQL statement, you will get an error.

Now that we've looked at the syntax for data shaping, we still have to examine how to obtain a data shape through ADO. We'll focus on this in Part 3 of this article!

  • Read Part 3
    (Read Part 1)


    Windows Internet Technology | ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article



  • JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Solutions
    Whitepapers and eBooks
    Microsoft Article: Will Hyper-V Make VMware This Decade's Netscape?
    Microsoft Article: 7.0, Microsoft's Lucky Version?
    Microsoft Article: Hyper-V--The Killer Feature in Windows Server 2008
    Avaya Article: How to Feed Data into the Avaya Event Processor
    Microsoft Article: Install What You Need with Windows Server 2008
    HP eBook: Putting the Green into IT
    Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
    Avaya Article: Setting Up a SIP A/S Development Environment
    IBM Article: How Cool Is Your Data Center?
    Microsoft Article: Managing Virtual Machines with Microsoft System Center
    HP eBook: Storage Networking , Part 1
    Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Intel Video: Are Multi-core Processors Here to Stay?
    On-Demand Webcast: Five Virtualization Trends to Watch
    HP Video: Page Cost Calculator
    Intel Video: APIs for Parallel Programming
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Sun Download: Solaris 8 Migration Assistant
    Sybase Download: SQL Anywhere Developer Edition
    Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
    Red Gate Download: SQL Compare Pro 6
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
    eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
    IBM Article: Collaborating in the High-Performance Workplace
    HP Demo: StorageWorks EVA4400
    Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
    Microsoft How-to Article: Get Going with Silverlight and Windows Live
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES