Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Combine 2 columns from 2 tables

Author  Topic 

msenthilrajanmca
Starting Member

3 Posts

Posted - 2008-05-23 : 09:45:43
Hi,

I have 2 tables called Table A, Table B,

In Table A i am having Data1, Data2 like 2 datas in Column 1
In Table B i am having Data2, Data3 Like 2 datas in Column 1

Now want a output like

Data1,
Data2,
Data3

Please help me to get this....

Thank you,
Senthil

pootle_flump

1064 Posts

Posted - 2008-05-23 : 09:51:39
Check out this SQL tutorial. In particular you will want to use UNION (ALL)

Oops - posting the link helps eh?
http://www.w3schools.com/sql/default.asp
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-23 : 10:04:26
[code]-- Prepare sample data
DECLARE @TableA TABLE (Col1 VARCHAR(20))

INSERT @TableA
SELECT 'Data1, Data2'

DECLARE @TableB TABLE (Col1 VARCHAR(20))

INSERT @TableB
SELECT 'Data2, Data3'

-- Show the expected output
SELECT LTRIM(RTRIM(x.Data)) AS theValue
FROM @TableA AS a
CROSS APPLY dbo.fnParseList(',', Col1) AS x

UNION

SELECT LTRIM(RTRIM(x.Data)) AS theValue
FROM @TableB AS b
CROSS APPLY dbo.fnParseList(',', Col1) AS x[/code]


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

pootle_flump

1064 Posts

Posted - 2008-05-23 : 10:33:29
Oh - two datums in one column. Sorry Sentil - I misunderstood.

You realise of course that you could do with changing the design if you can?
Go to Top of Page

msenthilrajanmca
Starting Member

3 Posts

Posted - 2008-05-24 : 01:27:12
Thank you friends
Go to Top of Page
   

- Advertisement -