User Profile

Collapse

Profile Sidebar

Collapse
GrandVizier
GrandVizier
Last Activity: Apr 5 '07, 11:25 PM
Joined: Mar 13 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Solution

    Code:
    SELECT		Res.rID, Res.rDate, Res.rName, Res.rTotalPass AS Total,
    		SUM(CASE WHEN Special.sAdult = 1 THEN Res2.r2Pass ELSE 0 END) AS Ad,
    		SUM(CASE WHEN Special.sChild = 1 THEN Res2.r2Pass ELSE 0 END) AS Child,
    		SUM(CASE WHEN Special.sInfant = 1 THEN Res2.r2Pass ELSE 0 END) AS Inf 
    FROM		Reservations AS Res
    INNER JOIN	Res2 ON Res2.rID = Res.rID
    LEFT JOIN	Special ON Special.sID = Res2.sID
    ...
    See more | Go to post

    Leave a comment:


  • I should point out that I get results like:
    Code:
    rID 	|	rDate		|	 rName		|	Total	|	 Ad 	|	Child 	|	Inf
    387	|	01/01/06	|	Harrison	|	3	|	3	|	0	|	0
    418	|	01/01/06	|	Childs		|	5	|	0	|	2	|	0
    418	|	01/01/06	|	Childs		|	5	|	3	|	0	|	0
    where I would like to see results like:
    Code:
    rID 	|	rDate		|	 rName		|	Total	|	 Ad 	|	Child 	|	Inf
    387	|	01/01/06	|	Harrison	|	3	|	3	|	0	|	0
    418	|	01/01/06	|	Childs		|	5
    ...
    See more | Go to post

    Leave a comment:


  • SELECT statement returns duplicate rows when a single row is desired

    Hej
    With SQL Server 2005 I'm trying to run a query that gets a passenger list from multiple tables. The ultimate goal is to output this information in a report.
    There are 3 tables (each of these have additional columns that aren't relevant to this query and have been left out of this example):
    RESERVATIONS
    rID | rDate | rName | rTotalPass

    RES2
    r2ID | rID | r2Pass | sID

    SPECIAL
    ...
    See more | Go to post
No activity results to display
Show More
Working...