te pregunte para que necesitabas esa variable y no me comentaste, aqui lo mas sencillo es que guardes el resultado en una variable de tipo tabla(hay una funcion para hacer lo que necesitas pero es mas codigo)
Código SQL:
Ver originalDECLARE @IdWagerParlay TABLE (id INT)
INSERT INTO @IdWagerParlay
SELECT D.[IdWager] FROM GRADEDWAGERDETAIL D, GRADEDWAGERHEADER H, GAME G, PERIOD P, AGENT A, WAGERTYPE W
WHERE D.[IdWager] = H.[IdWager] AND
D.[IdGame] = G.[IdGame] AND
H.[IdAgent] = A.[IdAgent] AND
H.[IdWagerType] = W.[IdWagerType] AND
D.[IdSport] = P.[IdSport] AND
D.[Period] = P.[NumberOfPeriod] AND
W.[Description] LIKE '%PARLAY%' AND
H.[SettledDate] >= CONVERT(datetime,('2014-01-16 00:00:01')) AND
H.[SettledDate] <= CONVERT(datetime,('2014-01-16 23:59:59')) AND
H.[IdAgent] = 5039
GROUP BY D.[IdWager]
SELECT * FROM GRADEDWAGERDETAIL D WHERE IdWager IN (SELECT * FROM @IdWagerParlay)
este es un modo y este es otro:
Código SQL:
Ver originalSELECT D.[IdWager] INTO #temp FROM GRADEDWAGERDETAIL D, GRADEDWAGERHEADER H, GAME G, PERIOD P, AGENT A, WAGERTYPE W
WHERE D.[IdWager] = H.[IdWager] AND
D.[IdGame] = G.[IdGame] AND
H.[IdAgent] = A.[IdAgent] AND
H.[IdWagerType] = W.[IdWagerType] AND
D.[IdSport] = P.[IdSport] AND
D.[Period] = P.[NumberOfPeriod] AND
W.[Description] LIKE '%PARLAY%' AND
H.[SettledDate] >= CONVERT(datetime,('2014-01-16 00:00:01')) AND
H.[SettledDate] <= CONVERT(datetime,('2014-01-16 23:59:59')) AND
H.[IdAgent] = 5039
GROUP BY D.[IdWager]
SELECT * FROM GRADEDWAGERDETAIL D WHERE IdWager IN (SELECT * FROM #temp)
saludos....