Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert Into error

Status
Not open for further replies.

IronIke

Programmer
Jun 14, 2001
10
US
I have a stored procedure that I want to make a copy of a row in a table, except to change the key field and a couple of others. Here is what I have so far:

Create Procedure procCreateAndCopy
@smpId as int
@smpNewId as int
As


Select *
Into #tmpSample
From Sample
Where smpId = @smpId

Update #tmpSample
Set smpId = @smpNewId,

Insert Into Sample
Select * From #tmpSample

It works fine unitl the Insert Into Sample. The error I get is:

Cannot insert a non-null value into a timestamp column. Use INSERT with a column list or with a default of NULL for the timestamp column.

I am hoping NOT to have to list all of the columns in the table due to both laziness on my part but also due to not wanting to have to modify the stored procedure if the table layout changes.

Thanks.
 
Time to bite the bullet and create that select list. You can also eliminate the temporary table and make the procedure much simpler.

Create Procedure procCreateAndCopy
@smpId as int
@smpNewId as int
As

-- Leave out the time stamp column
Insert Into Sample (smpId, smpCol2, smpCol3, ...)

-- Select the New ID and
-- other columns from table
Select @smpNewID, smpCol2, smpCol3, ...

From Sample
Where smpId = @smpId Terry L. Broadbent - Salt Lake City, UT
Home of the 2002 Winter Olympics (Feb 8-24)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top