SQL Server case statement

Posted on 2007-08-10
Last Modified: 2013-11-19
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
Question by:lrbrister
    LVL 142

    Accepted Solution

    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


    Author Comment

      As always...a pleasure.  Points being awarded now

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Building “do-it-yourself” web sites has become an epidemic. There are so many blogs, web sites and even books that "teach" you how to build your web site in a few extremely simple and easy steps. Building a web site has become easier than boiling an…
    I've been asked to discuss some of the UX activities that I'm using with my team. Here I will share some details about how we approach UX projects.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
    The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now