Advertisement

06.18.2008 at 05:13AM PDT, ID: 23494835
[x]
Attachment Details

TSQL - Select multiple rows into single row. (Master / detail tables)

Asked by Psychotext in SQL Query Syntax, MS SQL Server, SQL Server 2005

I am trying to put together a query that summarises a month worth of items in a detail table and I'm struggling a bit.  Basically what I want to have at the end is:

      Item 1 - 15 - £10
      Item 2 - 1 - £12
      Covers deliveries 1232, 1234, 502.  Dates 01/01/2000, 01/02/2000, 01/02/2000

The item rows are easy, but I'm not sure how to put together that final row.  Tables being worked with are something like this:

      Summary Table:
      ID
      Total
      Date

      Detail Table:
      ID
      SummaryID
      DeliveryNumber
      DeliveryDate
      
I can do a simple select to return all detail rows required (SELECT [DeliveryNumber], [DeliveryDate] FROM [DetailTable] WHERE [SummaryID] = @SummaryID) but I need to get this into a single row and formatted as closely as I can to the sample above.

Any solutions?Start Free Trial
 
Loading Advertisement...
 
[+][-]06.18.2008 at 05:28AM PDT, ID: 21812079

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: SQL Query Syntax, MS SQL Server, SQL Server 2005
Sign Up Now!
Solution Provided By: Chrisedebo
Participating Experts: 3
Solution Grade: A
 
 
[+][-]06.18.2008 at 06:24AM PDT, ID: 21812543

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]06.18.2008 at 06:26AM PDT, ID: 21812568

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628