Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 12th, 2007, 11:13 PM
Authorized User
Points: 336, Level: 6
Points: 336, Level: 6 Points: 336, Level: 6 Points: 336, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2006
Location: , , .
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
Reply With Quote
  #2 (permalink)  
Old November 12th, 2007, 11:38 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
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
================================================== =========
Reply With Quote
  #3 (permalink)  
Old November 13th, 2007, 12:58 PM
Authorized User
Points: 336, Level: 6
Points: 336, Level: 6 Points: 336, Level: 6 Points: 336, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2006
Location: , , .
Posts: 73
Thanks: 6
Thanked 0 Times in 0 Posts
Default

dparsons:

Thank you.. Worked perfectly.

Reply With Quote
  #4 (permalink)  
Old November 13th, 2007, 01:25 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
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
================================================== =========
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:18 PM.


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