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 2000 Forums
 Transact-SQL (2000)
 Insert the data from other table into temp table.

Author  Topic 

boyfriendalex
Starting Member

15 Posts

Posted - 2008-07-21 : 22:54:46
Hi everybody.

I want to insert the data into the temptable
the scripts is followed:

...
DELETE #TempList1
ALTER TABLE #TempList1
ADD column1 varchar(20)
DBCC CHECKIDENT ('#TempList1',RESEED,0)
SET IDENTITY_INSERT #TempList1 ON
INSERT INTO #TempList1 SELECT column1 FROM table1
SET IDENTITY_INSERT #TempList1 OFF
...
By the way errors happened.
An explicit value for the identity column in table
'#TempList1' can only be specified when a column list is used
and IDENTITY_INSERT is ON.

Anyone help?

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-07-21 : 23:10:19
Tried this?

INSERT INTO #TempList1(column1) SELECT column1 FROM table1
Go to Top of Page

boyfriendalex
Starting Member

15 Posts

Posted - 2008-07-22 : 00:09:00
quote:
Originally posted by rmiao

Tried this?

INSERT INTO #TempList1(column1) SELECT column1 FROM table1




Thank u.. but the other error happens..
i tried to add more columns to temp table
.....
ALTER TABLE #TempList
ADD column1 varchar(20),column2 varchar(20),column3 varchar(10)
....
the rest is the same
by the way occurs the error:
Invalid column name 'column1'
Invalid column name 'column2'
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-22 : 00:14:48
Can you create the temp table with all the required column there in the first place ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

boyfriendalex
Starting Member

15 Posts

Posted - 2008-07-22 : 00:23:34
quote:
Originally posted by khtan

Can you create the temp table with all the required column there in the first place ?


KH
[spoiler]Time is always against us[/spoiler]




Excuse me.. what do u mean by that?
you mean ALTER command has problem isn't it?
So when defining the temp, put the all required columns to the table, isn't it?
can u recommend the other solutions?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-07-22 : 00:31:57
yes. I mean when you are creating the temp table, create all the column1, column2 in there.

What is the reason you are not able to do this ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -