Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Stored procedure for cloning records
Message
From
04/11/2003 11:01:28
 
 
To
03/11/2003 16:27:32
General information
Forum:
Microsoft SQL Server
Category:
Stored procedures, Triggers, UDFs
Miscellaneous
Thread ID:
00845792
Message ID:
00846013
Views:
26
This message has been marked as the solution to the initial question of the thread.
>Can anyone help me?

How about something like this:
create proc sp_clone
(@tablename sysname
,@keyvalue int
)
AS 

DECLARE @sql varchar(8000)

SET
@sql = 'SELECT * INTO #temp FROM '+@tablename+' WHERE iid = '+cast(@keyvalue AS varchar(100))+' '
     + 'DECLARE @newid int '
     + 'exec @newid = sp_getnewid('''+@tablename+''') '
     + 'UPDATE #temp SET iid = @newid '
     + 'INSERT INTO '+@tablename+' SELECT * FROM #temp'

EXEC( @sql )

RETURN
BOb
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform