Help concat strings with a money column

  • I need some advice on this one.............

    I want to concatonate a bunch of fields to be one field such as:

    SET              concat_null_yields_null OFF                     

    SELECT   

     'Vendor: '+ vendor + '/n ' +

     'Check number: ' + [check] + '/n ' +

     'Amount: ' + str(amount) + '/n ' +

     'Account number: ' + str(actnum)

     The column 'amount' is originally a money field but str'd so that I can concatonate it with everthing else. I do however need it to ultimatley appear as $1,234.00 not the current 123400.............

  • You could do that kind of formatting at the front end.

    ******************
    Dinakar Nethi
    Life is short. Enjoy it.
    ******************

  • Try this:

    SELECT 'Vendor: '+ vendor + '/n '

         + 'Check number: ' + [check] + '/n '

         + 'Amount: $' + CONVERT(varchar(15), amount, 1) + '/n '

         + 'Account number: ' + str(actnum)

     

  • Thanks Oldhand that's perfect!

    Jeff

     

  • Just curious... what do YOU do when there is no front end as in when you're exporting files that have to meet certain formatting criteria?

    --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)

  •  

    Jeff,

    That's exactly what I'm up against.  I have to do everything in t-sql to create a .csv that's formatted properly.   Oldhand's solution is what I needed. I just concatonated a '$' in front of it and did a case when so I don't get and '$0.00' results.

    Jeff

     

     

     

  • Jeff,

    Actually, "Old Hand" is a status, not a name.  MKEast gave you that fine solution.  And, I sympathize with you... have had to do much formatting in SQL Server for the exact same reason.

    Anyway, thanks for the feedback.

    --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)

  •  

    Thanks MKEast !!!!!!!!!!!!!!!!!!!!!!!

Viewing 9 posts - 1 through 8 (of 8 total)

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