troubleshooting Question

How do i use Stored Proc to generate and return incremented primary key values?

Avatar of connelvalentine
connelvalentine asked on
Visual Basic.NET
1 Comment1 Solution212 ViewsLast Modified:

I'm using 2005 to create a database application with SQL server 2000 as a backend.
Here's my design. All my tables have got a standard format for the primary key. Eg. My "tbl_offices" table has got the primary key set as OFF0000001, OFF0000002, OFF0000003 and so on.
Whenever i add a new record, i want a stored procedure to be able to:
1. Connect to the offices table
2. Retrieve the records ordered by primrary key
3. Increment the last primary key number by 1.
4. Return the next primary key in the right format.

I'm new to stored procedures, so i'm NOT fully aware of how this can be done. Once the stored procedure is created, how can i store the return value in a variable in VB?

It'll be great if i can pass the table name to the procedure as a parameter, cause then i can use this one procedure to generate and return primary keys for all my tables and store them in my form.

Appreciate any help. Thanks

Best Regards,
Join our community to see this answer!
Unlock 1 Answer and 1 Comment.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros