|
-
Aug 28th, 2005, 06:56 AM
#1
Thread Starter
Lively Member
[RESOLVED] SQL (when an ID is deleted, the following ID will -1 to take the new position.
i have a ss_table which consist of sID, qnsID, ansID.
the values of sID are s0001, s0002, s0003 and so on.
If i were to remove s0002, i would like s0003 to shift up and set as s0002.
can someone show me how i can do this in sQL
my approach is rst.Open "SQL", cn, adOpenDynamic, adLockOptimistic
note: sID is set as 'Text' in Access table but autonumber-ed by SQL
rst!sID = "ss" & Right("0000" & CStr(CInt(rst1!ansID) + 1), 4)
Thank You
Astro
-
Aug 28th, 2005, 10:01 AM
#2
Re: SQL (when an ID is deleted, the following ID will -1 to take the new position.
Run this query right after you delete the record:
VB Code:
UPDATE ss_table
SET ss_table.sID = Left([sID],1) & Format(CLng(Mid([sID],2))-1,"0000")
WHERE (((ss_table.sID)>"s0002"));
Regards,
Mark
Please remember to rate posts! Rate any post you find helpful. Use the link to the left - "Rate this Post". Please use [highlight='vb'] your code goes in here [/highlight] tags when posting code. When a question you asked has been resolved, please go to the top of the original post and click "Thread Tools" then select "Mark Thread Resolved."
-
Aug 28th, 2005, 09:18 PM
#3
Thread Starter
Lively Member
Re: SQL (when an ID is deleted, the following ID will -1 to take the new position.
Hey Mark,
Brilliant! =) Pardon me for not having to mention that ss0002 will be removed when the referenced ansID (ans0001, ans0002, ans0003) is double clicked on.
rst1.Open "UPDATE ss_table SET ss_table.sID = Left([sID],1) & Format(CLng(Mid([sID],2))-1,'000000') WHERE '" & List3.Column(0, List3.ListIndex) & "' < ss_table.ansID", cn, adOpenDynamic, adLockOptimistic
How does this looks? note: i've changed 0000 to 000000.
-
Aug 28th, 2005, 10:15 PM
#4
Thread Starter
Lively Member
Re: SQL (when an ID is deleted, the following ID will -1 to take the new position.
Hey Mark,
I got it. Well actually i am asked to drop the idea. Great help anyway!
Thanks
Astro
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|