Click here to Skip to main content
11,477,625 members (78,161 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL SQL-Server
i HAVE GOT TWO COLUMNS COLUMN1 ADN COLUMN2. I want to store the values from column1 and two into a temporary table. How to acheive this?

column1 has values 1,2,3,4,5 and column 2 has values 6,7,8,9,10

i want a temporary table which contains all the values.

i.e
1
2
3
4
5
6
7
8
9
10
Posted 14-Dec-12 18:03pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Thanks everyone for your answers
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Here you go!!! everything about Temporary Table Quick Overview: Temporary Tables in SQL Server 2005[^][]

Declare @TempTableVariable TABLE(
UserID int,
UserName varchar(50), 
UserAddress varchar(150)) 
 
insert into @TempTableVariable values ( 1, 'Abhijit','India');
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,

Select * into temp_table (select column1 from table_name union all select column2 from table_name)
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hi,

Maybe this helps you :

IF OBJECT_ID('tempdb..#t1') IS NOT NULL DROP TABLE #t1
 
SELECT * INTO #t1 from
(
SELECT Column1
  FROM table1
  union
SELECT column2
  FROM table1) a
  
  SELECT * FROM #t1 


Good Luck
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 274
1 Richard Deeming 245
2 _duDE_ 165
3 Tomas Takac 150
4 Sascha Lefèvre 145
0 Sergey Alexandrovich Kryukov 7,675
1 OriginalGriff 7,246
2 Sascha Lefèvre 3,034
3 Maciej Los 2,491
4 Richard Deeming 2,305


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 15 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100