Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Stored procedure for cloning records
Message
De
04/11/2003 11:01:28
 
 
À
03/11/2003 16:27:32
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Divers
Thread ID:
00845792
Message ID:
00846013
Vues:
27
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform