October 17, 2014 at 5:01 pm
Hello,
I am currently working on extracting data from a text file and loading into sql server.
This is where I am stuck:
I have a table with 1 column and the data in the column is in this format:
TableName1
A
1
10
TableName2
D
2
20
I want to convert this to 2 columns in this format:
ColumnA ColumnB
TableName1 A
TableName1 1
TableName1 10
TableName2 D
TableName2 2
TableName2 20
Can anyone please help me to write a sql for this?
Thanks,
San
October 17, 2014 at 5:56 pm
You could do something like this:
SELECT 'TableName1' AS ColumnA,
SomeColumn AS ColumnB
FROM TableName1
UNION ALL
SELECT 'TableName2' AS ColumnA,
SomeColumn AS ColumnB
FROM TableName2
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply