Concatenate 2 columns into one but order by rows in SQL Query

I have 2 columns in SQL table.

Combine or concatenate these 2 columns and the output should be in single column but in row order. See attached.

Please help.

Thank you for your help.
Concatenate2ColumnsIntoOneButInRowO.xlsx
Queennie LAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bill PrewCommented:
I might be missing something, but this looks like it would be as below (I assumed you wanted a space between each concatenated value):

SELECT UniqueID, Column1, Column2, Column1+' '+Column2 AS Column3 FROM Table1

Open in new window



»bp
0
Queennie LAuthor Commented:
@Bill:

I would like the column3 to be in row order.

thank you.
0
Bill PrewCommented:
I would like the column3 to be in row order

I don't know what that means, can you clarify further please?


»bp
0
Acronis True Image 2019 just released!

Create a reliable backup. Make sure you always have dependable copies of your data so you can restore your entire system or individual files.

Bill PrewCommented:
Do you mean like this?

SELECT UniqueID, Column1, Column2, Column1+CHAR(10)+Column2 AS Column3 FROM Table1

Open in new window



»bp
0
Queennie LAuthor Commented:
@Bill:

Please see attached example.

Column3 should be:
AAAA
BBBB

Not like this: AAAA BBBB

Not in one row but 2 rows in one column.

Thank you.
0
Bill PrewCommented:
The output from my second query looks exactly like your Excel sample.

sshot-388.png

»bp
0
Queennie LAuthor Commented:
@Bill:

I will try it again.

Thank you.
0
Queennie LAuthor Commented:
@BILL:

I tried it but still one single line.

Thank you.
0
Bill PrewCommented:
Here is my test and the results, perhaps if you shared your query here.

EE29078966, Sql Server - rextester


»bp
0
Queennie LAuthor Commented:
@Bill:

In my query, still showing in one line. I know CHAR(10) is new line.

I don't know why my query is not populating correctly.

Thank you.
0
Bill PrewCommented:
How are you executing your query, in SSMS, or something else?


»bp
0
Bill PrewCommented:
If in SSMS then it doesn't look like it's grid presentation of the results honors the line fee or carriage return.  So don't think you can do it there.

You may have to take a different approach, or if the query is ultimately to be used in some other presentation tool (HTML, etc) then do the formatting there.


»bp
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Queennie LAuthor Commented:
@Bill:

This is just a simple tsql.

Thank you.
0
Bill PrewCommented:
I don't think you can get the effect you want in SSMS.


»bp
0
larryhSr. Software EngineerCommented:
How are you wanting to use the output of your query?  If you just want to be able to read it that's one thing but if you need to be able to cut/paste it into some other program that may be something else entirely.  There is output to text, grid and file in SSMS.  If we had more info on how you want to use the information that would help us help you better.
0
Queennie LAuthor Commented:
Thank you again for your help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.