Ver Mensaje Individual
  #2 (permalink)  
Antiguo 17/01/2014, 12:09
Avatar de Libras
Libras
Colaborador
 
Fecha de Ingreso: agosto-2006
Ubicación: En la hermosa perla de occidente
Mensajes: 7.412
Antigüedad: 18 años, 4 meses
Puntos: 774
Respuesta: Como unir los resultados de estos 2 select ?

uno regresa un valor de mas cierto, aqui lo que puedes hacer es esto:

Código SQL:
Ver original
  1. SELECT CONVERT(VARCHAR(8), G.[GradedDate] , 108) AS 'Time',
  2.        CONVERT(VARCHAR(MAX),G.[VisitorNumber]) + '/' + CONVERT(VARCHAR(MAX),G.[HomeNumber]) AS 'NumGame', G.[VisitorTeam] + ' @ ' +G.[HomeTeam] AS 'Teams', P.[PeriodDescription],
  3.        CONVERT(VARCHAR(MAX),G.[VisitorScore]) + ' - ' + CONVERT(VARCHAR(MAX),G.[HomeScore]) AS 'Score', COUNT(*) AS 'Tickets',
  4.        SUM(H.[RiskAmount]) AS 'Risk', A.[Agent], D.[RESULT], SUM(H.[WinAmount]) AS 'Win', D.[IdGame],0 AS IdWager
  5. FROM GRADEDWAGERHEADER H, GRADEDWAGERDETAIL D, GRADEDGAME G, PERIOD P, AGENT A, WAGERTYPE W
  6. WHERE H.[IdWager] = D.[IdWager] AND
  7.       D.[IdGame]  = G.[IdGame]  AND
  8.       H.[IdAgent] = A.[IdAgent] AND
  9.       H.[IdWagerType] = W.[IdWagerType] AND
  10.       H.[SettledDate] >= CONVERT(datetime,('2014-01-12 00:00:01')) AND
  11.       H.[SettledDate] <= CONVERT(datetime,('2014-01-12 23:59:59')) AND
  12.       D.[IdSport] = P.[IdSport] AND
  13.       D.[Period]  = P.[NumberOfPeriod] AND
  14.       W.[Description] LIKE '%STRAIGHT%' AND
  15.       H.[IdAgent] = 5585
  16. GROUP BY G.[GradedDate], G.[VisitorNumber], G.[HomeNumber], G.[VisitorTeam], G.[HomeNumber], G.[HomeTeam],
  17.          P.[PeriodDescription], G.[VisitorScore], G.[HomeScore], A.[Agent],D.[RESULT], D.[IdGame]
  18. UNION
  19. SELECT CONVERT(VARCHAR(8), G.[GradedDate] , 108) AS 'Time',
  20.        CONVERT(VARCHAR(MAX),G.[VisitorNumber]) + '/' + CONVERT(VARCHAR(MAX),G.[HomeNumber]) AS 'NumGame', G.[VisitorTeam] + ' @ ' +G.[HomeTeam] AS 'Teams', P.[PeriodDescription],
  21.        CONVERT(VARCHAR(MAX),G.[VisitorScore]) + ' - ' + CONVERT(VARCHAR(MAX),G.[HomeScore]) AS 'Score', COUNT(*) AS 'Tickets',
  22.        SUM(H.[RiskAmount]) AS 'Risk', A.[Agent], D.[RESULT], SUM(H.[WinAmount]) AS 'Win', D.[IdGame], D.[IdWager]
  23. FROM GRADEDWAGERHEADER H, GRADEDWAGERDETAIL D, GRADEDGAME G, PERIOD P, AGENT A, WAGERTYPE W
  24. WHERE H.[IdWager] = D.[IdWager] AND
  25.       D.[IdGame]  = G.[IdGame]  AND
  26.       H.[IdAgent] = A.[IdAgent] AND
  27.       H.[IdWagerType] = W.[IdWagerType] AND
  28.       H.[SettledDate] >= CONVERT(datetime,('2014-01-12 00:00:01')) AND
  29.       H.[SettledDate] <= CONVERT(datetime,('2014-01-12 23:59:59')) AND
  30.       D.[IdSport] = P.[IdSport] AND
  31.       D.[Period]  = P.[NumberOfPeriod] AND
  32.       W.[Description] LIKE '%PARLAY%' AND
  33.       H.[IdAgent] = 5585
  34. GROUP BY G.[GradedDate], G.[VisitorNumber], G.[HomeNumber], G.[VisitorTeam], G.[HomeNumber], G.[HomeTeam],
  35.          P.[PeriodDescription], G.[VisitorScore], G.[HomeScore], A.[Agent],D.[RESULT], D.[IdGame], D.[IdWager]

ya con eso puedes hacer el union :)
__________________
What does an execution plan say to t-sql query? Go f**k yourself, if you are not happy with me