To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Visual Basic > Office Development

Reply Post New Thread
 
Thread Tools Display Modes
Old Aug 28th, 2005, 06:56 AM   #1
Astro
Lively Member
 
Join Date: Jun 05
Posts: 90
Astro is an unknown quantity at this point (<10)
Resolved [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
Astro is offline   Reply With Quote
Old Aug 28th, 2005, 10:01 AM   #2
Mark Gambo
Giants World Champs!!!!
 
Mark Gambo's Avatar
 
Join Date: Sep 03
Location: Colorado
Posts: 2,965
Mark Gambo is a jewel in the rough (200+)Mark Gambo is a jewel in the rough (200+)Mark Gambo is a jewel in the rough (200+)
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:
  1. UPDATE ss_table
  2. SET ss_table.sID = Left([sID],1) & Format(CLng(Mid([sID],2))-1,"0000")
  3. 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."

Mark Gambo is offline   Reply With Quote
Old Aug 28th, 2005, 09:18 PM   #3
Astro
Lively Member
 
Join Date: Jun 05
Posts: 90
Astro is an unknown quantity at this point (<10)
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.
Astro is offline   Reply With Quote
Old Aug 28th, 2005, 10:15 PM   #4
Astro
Lively Member
 
Join Date: Jun 05
Posts: 90
Astro is an unknown quantity at this point (<10)
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
Astro is offline   Reply With Quote
Reply

Go Back   VBForums > Visual Basic > Office Development


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:30 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.