SQL help to CONCATENATE column values

  • I have another question about this.

    Instead of making the gradeServed format like K-05, how can I make the format like a string with each grade in order and no space in between:

    For K-05 , use 000102030405,

    for 09-12, change it to 09101112.

    For PS-5, make it like 00010203040529

    Thanks in advance

  • Gosh... I missed the additional question. My apologies for the delay.

    You'll need to do some conditional concatenation. Wayne Sheffield wrote a nice article on how to do such a thing. All you need to do is not include the commas he does. Here's the link to his article.

    http://www.sqlservercentral.com/articles/comma+separated+list/71700/

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • sqlfriends (5/3/2012)


    Is cross apply no longer available in SQL server 2008?

    It was not available in SQL Server 2000, so if your database is set to 2000 compatibility mode (80), you will get a syntax error when trying to use APPLY. It should not need saying that you should not be in 2000-compatible mode on SQL Server 2008 unless you have a particularly compelling reason. Note that this compatibility mode has been dropped from SQL Server 2012.

  • Thanks all, that is very helpful

Viewing 4 posts - 16 through 19 (of 19 total)

You must be logged in to reply to this topic. Login to reply