Select from table and back into table

I want to select a group of data from my maxallocation table then I want to insert back into that maxallocation table but with some of the values changed.  I get the error "There is already an object named 'maxallocation' in the database.".

Is there a better way to do this

Here is my code:

ALTER  PROCEDURE [dbo].GetLastAllocationSchedule   
    @StartDate nvarchar(30),
    @StopDate nvarchar(30)
AS

DECLARE @LastStartDate nvarchar(30)
DECLARE @LastStopDate nvarchar(30)

SELECT @LastStartDate = max(StartDate)
FROM maxallocation

SELECT @LastStopDate = max(StopDate)
FROM maxallocation

select
    m.[FundCode] as 'FundCode',
    f.[name] as 'FundName',
    @StartDate as startdate,
    @StopDate as stopdate,
    0 as 'FirstTier',
    0 as 'SecondTier',
    0 as 'ThirdTier',
    0 as 'FourthTier',
    0 as 'FifthTier'
into maxallocation
from maxallocation m
    inner join fund f
    on m.fundcode = f.fundcode
where m.startdate = @LastStartDate
    and m.stopDate = @LastStopDate


Answer this question

Select from table and back into table

  • ayala

    You cannot use the SELECT ... INTO with a table that already exists.  Use INSERT instead.

  • Select from table and back into table