Click here to Skip to main content
15,881,559 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

Thanks everyone for your answers
 
Share this answer
 
Hi,

Maybe this helps you :

SQL
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
 
Share this answer
 
Hi,

Select * into temp_table (select column1 from table_name union all select column2 from table_name)
 
Share this answer
 
Here you go!!! everything about Temporary Table Quick Overview: Temporary Tables in SQL Server 2005[^][]

C#
Declare @TempTableVariable TABLE(
UserID int,
UserName varchar(50), 
UserAddress varchar(150)) 

insert into @TempTableVariable values ( 1, 'Abhijit','India');
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900