Avatar of ttist25
ttist25
 asked on

SQL - Combine multiple fields from a table into a single column

Hello,

I'm trying to concatenate the values in multiple columns into a string in another column.

Here is some SQL:
CREATE TABLE #tmpExample ( 
    column1 varchar(255),
    column2 varchar(255),
    column3 varchar(255),
	column4 varchar(255)
);
INSERT INTO #tmpExample  
VALUES 
('1', 'A', 'B', 'C'),
('2', 'D', 'E', 'F'),
('3', 'G', 'H', 'I'),
('4', '', '4', 'ME');

ALTER TABLE #tmpExample
ADD columns2_4 varchar(255)

Open in new window


Given that data I would like to write a statement that results in the following in "columns2_4":
ABC
DEF
GHI
PIZZA4ME

I'm hungry right now and so I'm thinking ISNULL(COLUMN2, 'PIZZA').

Actually any NULL in column 2,3, or 4 should return pizza (I'm REALLY hungry).  

TIA!
Microsoft SQL Server

Avatar of undefined
Last Comment
ttist25

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Brendt Hess

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ttist25

ASKER
Great thanks Brendt!
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck