|
Home > Archive > MS SQL Server > November 2006 > Need Help Coalescing
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Need Help Coalescing
|
|
|
| Hi,
Below is the code I am struggling with. I want to return only those
"item_id(s)" that pertain to each member. The current results are
giving me every "item_id" for every member.
What am I doing wrong.
Thanks!!!
declare @Indicatorgroup varchar(8000)
select
@Indicatorgroup = coalesce(@Indicatorg
roup + ',','') + cast(item_id as
varchar)
from #temp_BLAH
group by Member, item_id
select +@Indicatorgroup, Member
from #temp_BLAH
group by Member
So the results now are like this:
A,B,C,D,E.....Z Smith, Ben
A,B,C,D,E.....Z Jones, Dave
But Ben only has A, C, and D.
So I'd like the results to be like:
A,C,D Smith,Ben
A,J,Q Jones,Dave
| |
| John Bell 2006-11-15, 5:13 am |
| Hi
The safe way to do this is to use a cursor if using SQL 2000 see
http://tinyurl.com/yat5xr
John
"Dubs" wrote:
> Hi,
>
> Below is the code I am struggling with. I want to return only those
> "item_id(s)" that pertain to each member. The current results are
> giving me every "item_id" for every member.
>
> What am I doing wrong.
>
> Thanks!!!
>
> declare @Indicatorgroup varchar(8000)
> select
> @Indicatorgroup = coalesce(@Indicatorg
roup + ',','') + cast(item_id as
> varchar)
> from #temp_BLAH
> group by Member, item_id
>
> select +@Indicatorgroup, Member
> from #temp_BLAH
> group by Member
>
> So the results now are like this:
> A,B,C,D,E.....Z Smith, Ben
> A,B,C,D,E.....Z Jones, Dave
>
> But Ben only has A, C, and D.
>
> So I'd like the results to be like:
>
> A,C,D Smith,Ben
> A,J,Q Jones,Dave
>
>
|
|
|
|
|