troubleshooting Question

Creating a stored procedure

Avatar of anthonytr
anthonytrFlag for United Kingdom of Great Britain and Northern Ireland asked on
Microsoft SQL Server.NET ProgrammingSQL
15 Comments2 Solutions194 ViewsLast Modified:

I'm new to (having moved from VBA) and I'm in the process of converting a simple database into using Visual Studio 2013.  I have quickly realised that stored procedures are going to be the way forward regarding updating my SQL database and for performing queries on such data.

Currently when I create a new batch associated with a customer in the database I check the tbl_batches table to see if that customer has already had a batch created and if they do I look for the most recent batch created and add 1 to that number and return that to the user.  If there are no batches in the the system for the customer then the batch numbering starts at 01.

The  VBA code I had for this action was:

1 + Nz(DMax("batch_number", "tbl_batches", "customer_id = '" & Me.customer_id & "'"), 0)

For the life of me I have no idea how this would convert into a stored procedure.  So that my form field gets filled with either a 01 if there is not batch for the client in the database or returns the most recent addition and adds 1 to this number (advancing the batch number by 1)
Join our community to see this answer!
Unlock 2 Answers and 15 Comments.
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 2 Answers and 15 Comments.
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