473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Sample Stored Procedures (ADP)

Does anyone know of a good place to get a couple of sample stored procedures for a .adp project in Access? Or maybe someone can just help with this question....

I know how to pull data out for single table:
ALTER PROCEDURE ArchiveLog
AS SELECT PROD_NAME, ARCHIVE_TS
ORDER BY PROD_NAME

but I need to make a query where, to simplify the problem, I've got the tables
DM_LABEL
L_DATA
V_DATA
PRODUCT
SG_DATA
and others
I need to get the VALUE column from V_DATA if the LABEL_ID = the LABEL_ID from L_DATA and if the NAME in L_DATA is = "Operator" and so on and so forth.

The database that I"m accessing is basically just a maze of these little tables that need to be accessed multiple times in order to get info like Lot number, Operator, Audit time, etc. The same thing needs to be repeated for values in other tables based on being linked to that particular audit.

The whole thing needs to be run based on a parameter provided by the user, so they could say that they only wanted products with part number 587 and lot number 32.

I'd love a shove in the right direction.
Sep 7 '07 #1
3 3560
Jim Doherty
897 Expert 512MB
Does anyone know of a good place to get a couple of sample stored procedures for a .adp project in Access? Or maybe someone can just help with this question....

I know how to pull data out for single table:
ALTER PROCEDURE ArchiveLog
AS SELECT PROD_NAME, ARCHIVE_TS
ORDER BY PROD_NAME

but I need to make a query where, to simplify the problem, I've got the tables
DM_LABEL
L_DATA
V_DATA
PRODUCT
SG_DATA
and others
I need to get the VALUE column from V_DATA if the LABEL_ID = the LABEL_ID from L_DATA and if the NAME in L_DATA is = "Operator" and so on and so forth.

The database that I"m accessing is basically just a maze of these little tables that need to be accessed multiple times in order to get info like Lot number, Operator, Audit time, etc. The same thing needs to be repeated for values in other tables based on being linked to that particular audit.

The whole thing needs to be run based on a parameter provided by the user, so they could say that they only wanted products with part number 587 and lot number 32.

I'd love a shove in the right direction.

Nice to see you working on Stored procedures Christina....

What I am going to relate to you now concerns bound forms ok? that is to say where your strategy is to bind the form to a recordsource and let access do the work navigating records and so on rather than you controlling it via ADO recordsets in code. Its the easiest to start with, without having to understand the syntax for ADO coding as well......information overload.... you can always do that later once you get the form interaction methodology of using an ADP form with a stored procedure.

Stored procedures accept parameters and the body of the procedure itself accepts the value of the parameter passed to it and responds accordingly a simple example of this is can be a basic select:

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE dbo.usp_ GetMyLabel
  2. (@label varchar(100))     -- <<<<<<this is the parameter passed in with datatype defined
  3. AS   --<<<< this AS word is part of the procedure
  4. -- and then the select statement using the parameter as part of the WHERE clause
  5. SELECT [VALUE] FROM vdata where [VALUE]=@label
  6.  
  7. GO
This returns to you a dataset ie a one column one row ([Value])
containing the values '12345' pre-supposing of course the table has the data.

So how did you 'pass' the parameter to the stored procedure from within your access form?.

Well lets say your form was purpose built to 'always' require that value as a dataset. The value would be passed as part of the FORMS InputParameters property (you see this by selecting View properties for the form its at the bottom of the dialog list.)

When the form opens it looks for its record source which, in this case would be the name of the stored procedure itself. It in turn looks to the inputparameter box if you like for the parameter.

Tip: (a must have) always use the 'owner' prefix (dbo) when using stored procedures or any view from an Access ADP this is very relevant if in a multi users environment particularly where users can create their own objects on the server from the client side.

So then the recordsource for the form as I said would be dbo.usp_GetMyLabel. The PARAMETERS for this stored procedure are typed into the InputParameters like this @label='12345'

All very well and good but not a good example, maybe so, but it is the barest in order to quickly understand the principle because from here you then build on that like so:

Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE dbo.usp_ GetMyLabel
  2.  (@namebeingpassedin-- <<<<<<this time the parameter passed in is variable parameter seeking name as you required
  3. AS   --<<<< this AS word is part of the procedure
  4. -- and here is the SQL statement
  5. SELECT  TOP 100 PERCENT [VALUE] as MyValue FROM dbo.vdata
  6. INNER JOIN dbo.L_DATA on dbo.vdata.LABEL_ID=dbo.L_DATA.LABEL_ID
  7. WHERE [NAME]=@namebeingpassedin
  8. ORDER BY v.data.[VALUE]
  9. GO

(Notice in the above syntax how I have changed the NAME value of the field to alias it as MyValue. Watch out for using reserved words and so on for field naming etc)

The above stored procedure (sproc as they become known) answers basically this bit of your question

I need to get the VALUE column from V_DATA if the LABEL_ID = the LABEL_ID from L_DATA and if the NAME in L_DATA is = "Operator"

Q) So how did the actual word 'Operator' get passed to the procedure?
A) It was passed in as a variable via the inputparameters section of the form properties

Q) How did we get the form to do this?
A) Create a continuous form with one textbox on it set the forms recordsource to dbo.usp_GetMyLabel. In Form design view type into the InputParameters property for the form this

@namebeingpassedin=[Enter the name to pass in]

This will bring you up a dialog prompt box (When you reopen the form) where you can physically type 'Operator' in alternatively you could use this

@namebeingpassedin=Forms!MyFormName!MyListbox

where the parameter value would then being sought on open from a listbox value mounted on your form if you wanted to do it that way, or it could be a textbox or option group value and so on.

So in short.... you do not need a mirad of stored procedures to achieve everything you want to achieve (my advice is to resist creating too many stored procedures where the only difference is a change in criteria) just identify the tables you wish to work with and create the SQL syntax to suit the circumstances passing into the stored procedure the WHERE clause argument value which on execution of the SQL will return the prescribed dataset to your form

I hope this helps you

Jim
Sep 7 '07 #2
Ok. I think I've got a lot to chew on for a while. Thanks, Jim!
Sep 10 '07 #3
Jim Doherty
897 Expert 512MB
Ok. I think I've got a lot to chew on for a while. Thanks, Jim!
As a PS I am on vacation as of today (off to sunny cyprus) so if you don't get a resolution you can PM me and I'll continue on return next week?

Jim
Sep 11 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Wim van Rosmalen | last post by:
I've upgraded MS-Access 2002 to a MS-Access Project (adp), so now I have to deal with more sophisticated queries (may I call them so?) like stored procedures. I have a form with a combobox for...
1
by: zlatko | last post by:
I use a stored procedure that is calling several other stored procedure which update or append values in several tables. All of them are stored procedures with input parameters by which they filter...
3
by: Ryan.Chowdhury | last post by:
This is a general question regarding the use of view and stored procedures. I'm fairly new to databases and SQL. I've created a SQL database using an Access Data Project ("ADP") and I'm...
3
by: Lauren Quantrell | last post by:
I am feeling a little overwhelmed trying to get my MDB-ADP conversion going. The first thing I need to figure out (very quickly) is how to use the values of unbound controls of forms in Stored...
1
by: thom | last post by:
Thanks in anticipation... I have an .adp where I connect to an MSDE sql backend. A number of networked PC's connect to this MSDE datasource. All PC's can see and connect to the sql service. ...
1
by: rdshultz | last post by:
Good morning everyone. Could someone tell me if there is a book out there which gives examples of both VB.net code and creating SQL Server 2000 stored procedures and how you get them to work...
3
by: Ed Pinnegar | last post by:
I've looked everywhere for info on stored procedures using Access. Any info on how to make one? Thanks! Ed
5
by: Tim Marshall | last post by:
I was following the thread "Re: Access Treeview - Is it Safe Yet?" with interest and on reading the post describing Lauren Quantrell's SmartTree, I've run into something I don't understand: Stored...
3
by: Darkside12 | last post by:
Hi, I'm trying to build a dynamic query by form. The idea is that a user can select a table in the database via a combo box and this will then change all of the text box labels on the form to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.