Left justification output

  • Could I get some expert help on how to make the output of this query left justified. Its a 10 character length output but its starting 5 spaces from the true starting point.

    REPLICATE(' ',10-LEN(

    ISNULL(

    CASE WHEN LTRIM(REPLACE(A.DIAGN1, '.','')) =''

    THEN NULL

    ELSE LTRIM(REPLACE(A.DIAGN1, '.',''))

    END

    , 'V689')

    ))+ISNULL(

    CASE WHEN LTRIM(REPLACE(A.DIAGN1, '.','')) =''

    THEN NULL

    ELSE LTRIM(REPLACE(A.DIAGN1, '.',''))

    END

    , 'V689') AS PRIME_DIAGN_CODE, --ISNULL(LEFT(' '+REPLACE(A.DIAGN1, '.',''), 10), LEFT(''+'V689'

    Thanks in advance...

  • What you have is code that will add the necessary leading spaces up to 10. In effect it will leave you with a right-aligned 10 character field.

    It is unnecessarily complicated, IMHO, but that's what it does.

    If you want the field to be left-aligned, then simply delete the first half (up to and including the plus-sign). The first half is what adds the spaces to right-align up to a field-lenght of 10.

Viewing 2 posts - 1 through 1 (of 1 total)

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