Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
sinjin67
Yak Posting Veteran
53 Posts |
Posted - 2008-03-26 : 17:27:36
|
| Good Day,I have an SQL 2005 Server running with a table calledActive and a linked table called Recall.In my .net APP I wrote a VB code that will copy anexisting record and create a duplicate with a new PK ID.Now here is the problem, The copy record works perfect if I create a new record and then copy that record. I canpress my copy button and it will make as many copies asI want. When I try to copy a record that is pre-existingfrom an import I did about 6 months ago it looks like itworks but the record is never copied.My question come down to, Is their something within SQL thatwould prohibt a record from being copied ? If the answer is yes, Can anyone advise where to look to change setting in SQL or what type of correction I shouldpursue.I am new to SQL and coming from a foxpro arena, Which is alsowhere the imported data came from..Any advice would be great.Thank You.. |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2008-03-26 : 21:55:07
|
| Why are you doung this in the app?Simpler to pass the PK to an SP and let it do the insert.As to why it doesn't work with old rows - probably because there's something wrong with the data you are trying to insert (notice how easy this would be to check with the SP?).You are maybe getting an error but not trapping iy.Try using the profiler to trace the sql executed and then execute it im management studio in a transaction with a rollback to see if it errors.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
sinjin67
Yak Posting Veteran
53 Posts |
Posted - 2008-04-09 : 13:10:36
|
| As I am coming from Visual Foxpro into SQL I am not that great with SP's. Any chanceyou might have a base example you couldshare to get me in the right direction.Thanx |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2008-04-09 : 13:14:48
|
| depends on you structure something like this for an identity PK. It takes the PK to copy and returns the new PK as an output parameter.create proc s_CopyRec@PK int ,@NewPKVal intasinsert mytbl (col1, col2, col3)select col1, col2, col3from mytblwhere PKCol = @PKColselect @NewPKVal = scope_identity()go==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-04-09 : 13:16:52
|
| [code]CREATE PROCEDURE CopyRecord@PKValue intASINSERT INTO YourTable (Field1,Field2,..)SELECT Field1,Field2,..FROM YourTableWHERE PKCol=@PKValueGO[/code] |
 |
|
|
sinjin67
Yak Posting Veteran
53 Posts |
Posted - 2008-04-09 : 16:22:28
|
| Thanks, I will work with the examples givin.. |
 |
|
|
|
|
|
|
|