In many databases the address is properly separated into various columns but in a report you want to concatenate them.
This simple script will pull them together in one column without causing extra spaces
SELECT ltrim(isnull([address], '') + ' ' + isnull([address2], '') + ' ' + isnull([city], '') + ' ' + isnull([state], '') + ' ' + isnull([zip], '')) AS "Address" FROM table
SELECT ltrim(CONCAT_WS('', p.firstname, ' ', p.middlename, ' ', p.lastname)) AS 'Patient Name'
FROM patient p;
Originally Posted on August 7, 2015
Last Updated on October 17, 2021
Last Updated on October 17, 2021
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.