OBL
OBL

Reputation: 1357

sql truncate/pad strings

I need something like this,

SELECT CLIENT_AHCCCS_ID + CLIENT_FIRST_NAME + CLIENT_LAST_NAME + replace(convert(datetime, DATE_OF_BIRTH, 1), '/', '')
FROM  tblCLIENT
WHERE CLIENT_AHCCCS_ID IS NOT NULL AND CLIENT_AHCCCS_ID LIKE 'A%'

But have to make sure that

CLIENT_AHCCCS_ID        ( 9 character )
Member Last Name      ( 25 character )
First Name          ( 25 character )

I have to use spaces to pad the string. How could I achieve this?

Upvotes: 2

Views: 1057

Answers (1)

David Hedlund
David Hedlund

Reputation: 129792

Assuming SQL Server, the SQL datatype char pads with strings, so you could always convert to that:

SELECT
    CONVERT(char(9), CLIENT_AHCCCS_ID) +
    CONVERT(char(25), CLIENT_FIRST_NAME) +
    CONVERT(char(25), CLIENT_LAST_NAME) +
    replace...

Upvotes: 4

Related Questions