BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

swapping two values in db

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Pascal Schmidt-Volkmar
Guest





PostPosted: Mon Dec 29, 2003 7:21 am    Post subject: swapping two values in db Reply with quote



Hi there,

I have entries in my db, each having a unique number. Now I would like to
change two entries so they just swap their numbers.

example: entry A with number 2
entry B with number 3

later: entry A with number 3
entry B with number 2

How could this be done? I tried a stored procedure but I failed because
after changing the first of both values, the primary key was violated. Maybe
I do need a third variable to store one of the two numbers....

Thanks for any help!!

Pascal


Back to top
Bill Todd (TeamB)
Guest





PostPosted: Mon Dec 29, 2003 12:43 pm    Post subject: Re: swapping two values in db Reply with quote



Please do not multipost or cross post your messages. It violates
Borland's guidelines for using their newsgroups and wastes everyone's
time. Please post one message in the most appropriate newsgroup and
please take a moment to read the newsgroup guidelines at
http://info.borland.com/newsgroups/guide.html

Change A to 99.
Change B to 2.
Change A to 3.

--
Bill (TeamB)
(TeamB cannot respond to questions received via email)
Back to top
Mehrdad Momeni
Guest





PostPosted: Mon Dec 29, 2003 1:58 pm    Post subject: Re: swapping two values in db Reply with quote



Hi

You should use a temp value - some thing that never happens in real world.
If your primary keys are auto generated (like identites in MS SQL Server),
and if they start with positive numbers, then one good candidate for the
temp value is the negate of first record's key.

cheers


Back to top
Dmeister
Guest





PostPosted: Tue Dec 30, 2003 12:52 pm    Post subject: Re: swapping two values in db Reply with quote

You've violated a basice database design rule by associating intelligence
with your Primary key. Your primary key should never be touched once
created. You should have a completely agnostic PK in addition to your
unique number field which you can manipulate to your heart's content.

"Pascal Schmidt-Volkmar" <pascalsv (AT) nospam_tauth (DOT) com> wrote

Quote:
Hi there,

I have entries in my db, each having a unique number. Now I would like to
change two entries so they just swap their numbers.

example: entry A with number 2
entry B with number 3

later: entry A with number 3
entry B with number 2

How could this be done? I tried a stored procedure but I failed because
after changing the first of both values, the primary key was violated.
Maybe
I do need a third variable to store one of the two numbers....

Thanks for any help!!

Pascal





Back to top
Brett Watters
Guest





PostPosted: Tue Dec 30, 2003 6:58 pm    Post subject: Re: swapping two values in db Reply with quote

Pascal,

Create column C.

Set C = A

then

Set A = B and
B = C

finally,

Drop column C.

Thanks,

Brett


"Pascal Schmidt-Volkmar" <pascalsv (AT) nospam_tauth (DOT) com> wrote

Quote:
Hi there,

I have entries in my db, each having a unique number. Now I would like to
change two entries so they just swap their numbers.

example: entry A with number 2
entry B with number 3

later: entry A with number 3
entry B with number 2

How could this be done? I tried a stored procedure but I failed because
after changing the first of both values, the primary key was violated.
Maybe
I do need a third variable to store one of the two numbers....

Thanks for any help!!

Pascal





Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (SQL Servers) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.