Concantenate SQL, need help
I have a Table where columns 8, 9, 10, 11, and 12 need to be concatenated into a single column CUST_ADDRESS. I've already added the new column to the end of the Table.
column 8 is: ADDRESS
column 9 is: ADDRESS 2
column 10 is: CITY
column 11 is: STATE
column 12 is: ZIP-CODE
ADDRESS( )ADDRESS 2( )CITY(, )STATE( )ZIP
I've done some research already and I think I found something that will work. The only problem is that I only need the 5 columns to be concatenated, there is 23 columns total in the Table. Also (this is not a big deal), but not sure if it would be possible to also use a ", " between the CITY and STATE and the rest can use a SPACE in the concatenation.
Help would be appreciated, thanks!
def Delimiter=" "
SELECT
ID,
SUBSTR(MAX(REPLACE(
SYS_CONNECT_BY_PATH(STRVAL, '/')
,'/','&Delimiter')),2) Concatenated_String
FROM (
select A.*,
row_number() OVER (Partition by ID order by ID) ROW#
from TMP_TEST A)
START WITH ROW#=1
CONNECT BY PRIOR ID=ID AND PRIOR row# = row# -1
GROUP BY ID;