Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Subquery

Status
Not open for further replies.

sardinka2

Programmer
May 6, 2004
38
0
0
US
I have the following code where I have some subquery. However my subquery return more than 1 row. Is it some how I can put all subquery result in 1 row instead of couple?
select Custom1=(select case Answer when 'Yes' then 'Y' else 'N' end + ' '
fromAnswers wa where wa.tranid=wt.TranID ),
....
FROM trans wt ....
more joins
 
I think u can use the sum() for the case,as follows

sum(select case Answer when 'Yes' then 1 else 0 end + ' '
-----
-----))
...
...
more joins
 
Not really. I need to display all Yes and No. Not just a sum
 
Use TOP 1 and optionally ORDER BY in subquery. But...

What if there are two records for the same TranID, one with Answer = 'Yes', another with 'No'. Which one is correct?
 
I have 7 answers with possible combinations 'Yes' and 'No'.
Maybe temp tamp will work? In a temp i will need to have the data store like this:
Answer TranID
Y Y Y .. 123
can you help me write this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top