SQL Server case statement

I need (I believe) a case stement that will struing together data based on a particular month

The result I want is

JanPO                                             FebPO   etc...
12345, 12346, 12347                      56789, 56799

from the data below

Month           po_num
1                    12345
1                     12346
1                    12347
2                     56789
2                     56799
Larry Bristersr. DeveloperAsked:
Who is Participating?
Guy Hengel [angelIII / a3]Billing EngineerCommented:
no, you will need a function:

create function dbo.ConcatMonthData(@month int)
returns varchar(100)
  declare @res varchar(100)
  select @res = coalesce(@res +',','') + cast(po_num as varchar(10))
  from yourtable
  where [month] = @month
  return (@res)

select dbo.ConcatMonthData(1) as JanPO
, dbo.ConcatMonthData(2) as FebPO

Larry Bristersr. DeveloperAuthor Commented:
  As always...a pleasure.  Points being awarded now
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.