Search code examples
sqlsql-server-2008stored-proceduresinsert-update

Updating a Table after some values are inserted into it in SQL Server 2008


I am trying to write a stored procedure in SQL Server 2008 which updates a table after some values are inserted into the table.

My stored procedure takes the values from a DMV and stores them in a table. In the same procedure after insert query, I have written an update query for the same table.

Insert results are populated fine, but the results of updates are getting lost.

But when I try to do only inserts in the stored procedure and I execute the update query manually everything is fine.

Why it is happening like this?


Solution

  • there should not be a problem in this.

    below code working as expected.

    create procedure dbo.test
    
    as
    
    begin 
    
    create table #temp (
    name varchar(100) ,
    id int
    )
    
    insert #temp
    select name ,
           id 
    from master..sysobjects
    
    update #temp
    
    set name='ALL Same'
    
    from #temp
    
    select * from #temp
    
    drop table #temp
    
    end
    go