sql截断/填充字符串

时间:2012-04-24 15:58:15

标签: sql string

我需要这样的东西,

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%'

但必须确保

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

我必须使用空格来填充字符串。我怎么能做到这一点?

1 个答案:

答案 0 :(得分:4)

假设SQL Server,SQL数据类型char填充字符串,因此您始终可以转换为:

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