Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select two columns for two different tables in SQL Server 2000

Tags:

sql-server

I have a database with two tables (Table1 and Table2). Table1 has one column ColumnA and Table2 has one column ColumnB i want to select both the columns,

looking for something like:

ColumnA in Table1:

a

b

c

ColumnA in Table2:

d

e

f

Result set should be:

a d

b e

c f

Thanks in advance..

like image 624
BABA Avatar asked Dec 17 '25 23:12

BABA


1 Answers

I am pretty sure sql server 2000 supports table vars so you can try this

DECLARE @TableA TABLE(
        ID INT IDENTITY(1,1),
        Val VARCHAR(50)
)

INSERT INTO @TableA (Val) SELECT ColumnA FROM Table1

DECLARE @TableB TABLE(
        ID INT IDENTITY(1,1),
        Val VARCHAR(50)
)

INSERT INTO @TableB (Val) SELECT ColumnB FROM Table2

SELECT a.Val,
        b.Val
FROM    @TableA a INNER JOIN
        @TableB b ON a.ID = b.ID
like image 68
Adriaan Stander Avatar answered Dec 20 '25 16:12

Adriaan Stander



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!