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)
 how to combine two queries?

Author  Topic 

k_cire0426
Yak Posting Veteran

63 Posts

Posted - 2009-03-30 : 17:19:38
query 1
col1 col2
2007 test

query 2
col1 col2
2008 test2


result
col1 col2 col3 col4
2007 test 2008 test2

any ideas?

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2009-03-30 : 17:21:45
Post your actual query's. The quick solution is to just add a row_Number then join the tables.


Success is 10% Intelligence, 70% Determination, and 22% Stupidity.
\_/ _/ _/\_/ _/\_/ _/ _/- 881
Go to Top of Page

k_cire0426
Yak Posting Veteran

63 Posts

Posted - 2009-03-30 : 17:28:28
query 1
select * from table1 where col1 = test

query 2
select * from table1 where col1 = test2
Go to Top of Page

Vinnie881
Master Smack Fu Yak Hacker

1231 Posts

Posted - 2009-03-30 : 17:30:26
[code]
Select *
from
(Select Row_Number() over (Order by Col1) as RowID,*
From Table1 where Col1 = 'Test') a
Inner join
(Select Row_Number() over (Order by Col1) as RowID,*
From Table1 where Col1 = 'Test2') b
on a.RowID = b.RowID
[/code]


Success is 10% Intelligence, 70% Determination, and 22% Stupidity.
\_/ _/ _/\_/ _/\_/ _/ _/- 881
Go to Top of Page
   

- Advertisement -