Reformatting formatted address fields

Last updated:

    Overview

    This section explains how to reformat an address field.

    Reformatting formatted address fields

    In this example, the address field from the Meetings section in the application may have been formatted.  The pdf only allows for a single line of text.  The following listing shows how to remove any formatting from the relevant fields, adding back a comma where appropriate:

    INSERT INTO @Data
    SELECT 'MeetLoc',
            (SELECT MeetLoc = REPLACE(REPLACE(MeetingLocation, CHAR(13),''), CHAR(10),', ') 
                    + ', ' + REPLACE(REPLACE(MeetingAddress, CHAR(13),''), CHAR(10),', ')
            FROM dbo.Meeting
            WHERE MeetingID = @MeetingID)