Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 194
  • Last Modified:

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
0
lrbrister
Asked:
lrbrister
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
no, you will need a function:

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


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

0
 
lrbristerAuthor Commented:
angelIII:,
  As always...a pleasure.  Points being awarded now
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now