How can I improve this Mailing Address SQL Server SELECT Statement?

后端 未结 3 1056
旧时难觅i
旧时难觅i 2020-12-11 10:43

How can I format a Mailing Address so that I always push all non-null rows to the top? That is, I want to convert an address from the structure below to a mailing address.<

3条回答
  •  悲&欢浪女
    2020-12-11 11:07

    SELECT 
        LTRIM(RTRIM(LINE1)) + LTRIM(RTRIM(LINE2)) + LTRIM(RTRIM(LINE3)) AS MailAddress1,
        LTRIM(RTRIM(CITY)) + ' ' + LTRIM(RTRIM(STATE)) + ' ' + LTRIM(RTRIM(POSTALCODE)) AS MailAddress2
    FROM MyTable
    

提交回复
热议问题