Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 12th, 2007, 11:13 PM
Authorized User
 
Join Date: Sep 2006
Posts: 73
Thanks: 6
Thanked 0 Times in 0 Posts
Default Combine Multiple Rows into One Row

Hello all:

I would like to know if the the following info below can be done.
I am using SQL Server 2000 and I can only perform lookups.

Here is an example of current table data.

Date Time Procedure Result
-------------- ------- --------- ------
12-Jul-2007 10:00 HGB 10.5
12-Jul-2007 10:00 HCT 31.0
13-Jul-2007 11:00 HGB 11.0
13-Jul-2007 11:00 HCT 33.0


What I would like it to look like is:

Date Time HGB HCT
----------- ----- ----- -----
12-Jul-2007 10:00 10.5 31.0
13-Jul-2007 11:00 11.0 33.0


Thanks,
Tony
 
Old November 12th, 2007, 11:38 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

You will need to use a subquery something like:

select distinct
    t1.date,
    t1.timeRec,
    (SELECT result from <yourtablename> where date = t1.date and [procedure] = 'HGB') as HGB,
    (SELECT result from <yourtablename> where date = t1.date and [procedure] = 'HCT') as HCT
FROM <yourtablename> t1

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
 
Old November 13th, 2007, 12:58 PM
Authorized User
 
Join Date: Sep 2006
Posts: 73
Thanks: 6
Thanked 0 Times in 0 Posts
Default

dparsons:

Thank you.. Worked perfectly.

 
Old November 13th, 2007, 01:25 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

glad it worked for you

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========





Similar Threads
Thread Thread Starter Forum Replies Last Post
Help: Need to combine multiple IF queries scotts SQL Server 2005 1 April 14th, 2008 07:54 PM
Combine multiple records onto one line bcahillane MySQL 0 December 6th, 2006 04:54 PM
print multiple times..multiple rows... abhit_kumar JSP Basics 3 January 18th, 2005 07:11 PM
HELP - Combine Rows in a View HenryE SQL Server 2000 1 July 22nd, 2004 12:58 AM
Updating multiple Rows from multiple fields in ASP vdm_nana SQL Server ASP 0 April 1st, 2004 04:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.