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.
| Author |
Topic |
|
samsun125
Yak Posting Veteran
63 Posts |
Posted - 2009-06-05 : 09:14:29
|
| Hi all,i have one query,in my sp i want to create one temparory table (with 3 columns)first 2 columns i want to take from one table .in 3rd column i want to give 1,2,3,4,5,6,7.how to do that .ex:create proc test()create #temptable(empid int,empname varchar(50),deptid int)here empid,empname i will take from one table , deptid i want to insert 1,2,3,4,5,6.how to do please help meThanks & RegardsRama |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-06-05 : 09:19:35
|
[code]insert into #temptable (empid, empname, deptid)select empid, empname, deptid = row_number() over (order by empid)from one_table[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-06-05 : 09:44:31
|
| Provided OP uses SQL Server 2005 or aboveMadhivananFailing to plan is Planning to fail |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2009-06-05 : 11:19:33
|
| [code]create proc test()create #temptable(empid int,empname varchar(50),deptid int IDENTITY(1,1))INSERT #Temptable (empid, empname)SELECT empid, empnameFROM TalbeOne[/code] |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-05 : 12:59:39
|
or you can create table on the fly as followsSELECT empid, empname,IDENTITY(int,1,1) AS deptid INTO #TempTable FROM TalbeOne |
 |
|
|
|
|
|
|
|