March 26, 2018 at 12:26 am
hello guys, I think this could be simple I can't seem to find a solution.
I have this table with multiple lines in a row.
Ex:
Table1
id Data1 Data2
1 B1 100
B2 50
-----------------------
2 M1 123
M2 160
M3 101
______________
I need to create a query to combine those two columns in a new column but side by side.
Desired output:
CombineX
B1-100
B2-50
M1-123
M2-160
M3-101
select concat is okay if the data does not have multiple lines, but if the data has multiple lines, select concat output is not side by side.
I don't need any conditions, I just want to combine or merge the 2 columns but it should be sideways, with a delimiter in between.
Thank you for any help.
April 4, 2018 at 9:04 am
The MySQL data would appear to contain carriage return characters which can be handled with REPLACE.
As for the layout, here is a starting point...
select Data1 AS CombineX FROM Table1
UNION ALL
select Data2 FROM Table1
LIMIT 30 ;
again REPLACE can be used to turn a space into a dash ... 'B2 50' becoming 'B2-50'
The below link gives good information on how to ask for help...
http://www.sqlservercentral.com/articles/Best+Practices/61537/
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy