Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2011-05-11 : 14:46:47
|
| I need to write a subquery such that I should grab a value from the first select statement and use it in the two where conditions of the second select statementBelow is my second querySelect C1.CustName,sum(C1.Members) TotalMembers,max(C1.NDATE) NDATE,min(C1.ODATE) ODATE ,sum(C1.SUBS) Subs,C2.MIDname,C1.Ftype, STUFF((SELECT ',' + CID FROM CustID where MID = 'xxxxxx' FOR XML PATH('')), 1, 1, '') AS CID From CustID C1 INNER JOIN CUSTMASTER C2 ON C1.MID = C2.MID where C1.MID = 'xxxxxx'group by C1.CustName,C2.MIDNAME,C1.Fundingtype |
|
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2011-05-11 : 15:16:03
|
| Please advise whther the below is a good approachSelect C1.CustName,sum(C1.Members) TotalMembers,max(C1.NDATE) NDATE,min(C1.ODATE) ODATE ,sum(C1.SUBS) Subs,C2.MIDname,C1.Ftype,STUFF((SELECT ',' + CIDFROM CustID where MID in (Select MID from Reqinfo where ReqinfoId = xxxxxx)FOR XML PATH('')), 1, 1, '') AS CIDFrom CustID C1 INNER JOIN CUSTMASTER C2ON C1.MID = C2.MIDwhere C1.MID in (Select MID from Reqinfo where ReqinfoId = xxxxxx)group by C1.CustName,C2.MIDNAME,C1.Fundingtype |
 |
|
|
|
|
|
|
|