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 |
|
markshen2006
Starting Member
15 Posts |
Posted - 2008-04-15 : 16:52:47
|
| HiI have two tables and I need write a query that include subquery that return more than 1 value,Can you give me a idea how to write the queryThe table with data is like this,one file maybe belong to many group.Filename FilegroupIDfile1 1file2 2file1 3file1 4file3 1file2 5I need write a query to get the result like thisfile1 1,3,4file2 2,5file3 1I try to write a query with subquery but I get error message"Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression"I use SQL Server 2005.but I need the subquery return data like "1,3,4".Please help me.ThanksMark |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
markshen2006
Starting Member
15 Posts |
Posted - 2008-04-15 : 20:47:32
|
| Hi Peso,I have taken look the link you posted, but I do not think I can get answer from that post.Please help me or give me other solution.ThanksMark |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-04-15 : 23:36:35
|
| Why do you think link Peso gave you dont work for you? |
 |
|
|
ranganath
Posting Yak Master
209 Posts |
Posted - 2008-04-16 : 00:43:34
|
| Hi,use thisdeclare @StrConcat table (col1 nvarchar(10),col2 nvarchar(10))insert into @StrConcatselect 'file1','1' union all select 'file1','2'union all select 'file1','3'union all select 'file2','1' union all select 'file2','2'union all select 'file3','2' union all select 'file3','3'select col1, stuff( ( select ','+ col2 from @StrConcat t1 where t2.col1 = t1.col1 for xml path('')),1,1,'') GroupIdfrom @StrConcat t2group by col1order by col1 |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-04-16 : 02:59:43
|
quote: Originally posted by markshen2006 Hi Peso,I have taken look the link you posted, but I do not think I can get answer from that post.Please help me or give me other solution.ThanksMark
If you use SQL Server 2005, then it would workOtherwise you need to have a user defined functionMadhivananFailing to plan is Planning to fail |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-04-16 : 03:06:04
|
quote: Originally posted by markshen2006 I have taken look the link you posted, but I do not think I can get answer from that post.
You "think" or you have test so that you know for fact? E 12°55'05.25"N 56°04'39.16" |
 |
|
|
markshen2006
Starting Member
15 Posts |
Posted - 2008-04-16 : 09:51:07
|
| Thanks |
 |
|
|
|
|
|
|
|