473,394 Members | 1,703 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,394 software developers and data experts.

Please convert access query into equivalent stored procedure

Hi ,

Can anybody convert below access query into equivalent stored procedure.
Also please advice in the below query,user defined function of VBA i.e anneeSelection41510() has been used in the .MDB file(access project).Now how this can be implemented in the equivalent .ADP(client/server architechture)project because obviously anneeSelection41510() function will not be recognised by the sql server." (t_activity_month.fy)=anneeSelection41510()) ".
Hope,you will help me out in this.

SELECT t_customer.code_customer, t_customer.name_customer, t_activity_brand1.no_activity AS Expr1, t_product.code_product, t_product.product_name, [price_off_amount1]*[nb_std_bt_planned1] AS mnt1, [price_off_amount2]*[nb_std_bt_planned2] AS mnt2, [price_off_amount3]*[nb_std_bt_planned3] AS mnt3, nz([mnt1],0)+nz([mnt2],0)+nz([mnt3],0) AS tot_mnt_mo, t_activity_brand1.price_off_customer_invoice AS Expr2, t_activity_brand1.price_off_active_invoice AS Expr3, t_activity.no_activity_month, t_activity_month.fy, t_activity_brand1.activity_brand_cancelled AS Expr4, t_activity.activity_cancelled
FROM t_product, t_activity_brand1, t_activity_month INNER JOIN (t_customer INNER JOIN t_activity ON t_customer.code_customer = t_activity.code_customer) ON t_activity_month.no_activity_month = t_activity.no_activity_month
WHERE (((t_activity_month.fy)=anneeSelection41510()) AND ((t_activity.activity_cancelled)=False Or (t_activity.activity_cancelled) Is Null) AND (([t_activity_brand1].[price_off_diageo_invoice])=True) AND (([t_activity_brand1].[activity_brand_cancelled])=False Or ([t_activity_brand1].[activity_brand_cancelled]) Is Null));

Many Thanks!

shovan
Dec 13 '07 #1
1 5582
Jim Doherty
897 Expert 512MB
Hi ,

Can anybody convert below access query into equivalent stored procedure.
Also please advice in the below query,user defined function of VBA i.e anneeSelection41510() has been used in the .MDB file(access project).Now how this can be implemented in the equivalent .ADP(client/server architechture)project because obviously anneeSelection41510() function will not be recognised by the sql server." (t_activity_month.fy)=anneeSelection41510()) ".
Hope,you will help me out in this.

SELECT t_customer.code_customer, t_customer.name_customer, t_activity_brand1.no_activity AS Expr1, t_product.code_product, t_product.product_name, [price_off_amount1]*[nb_std_bt_planned1] AS mnt1, [price_off_amount2]*[nb_std_bt_planned2] AS mnt2, [price_off_amount3]*[nb_std_bt_planned3] AS mnt3, nz([mnt1],0)+nz([mnt2],0)+nz([mnt3],0) AS tot_mnt_mo, t_activity_brand1.price_off_customer_invoice AS Expr2, t_activity_brand1.price_off_active_invoice AS Expr3, t_activity.no_activity_month, t_activity_month.fy, t_activity_brand1.activity_brand_cancelled AS Expr4, t_activity.activity_cancelled
FROM t_product, t_activity_brand1, t_activity_month INNER JOIN (t_customer INNER JOIN t_activity ON t_customer.code_customer = t_activity.code_customer) ON t_activity_month.no_activity_month = t_activity.no_activity_month
WHERE (((t_activity_month.fy)=anneeSelection41510()) AND ((t_activity.activity_cancelled)=False Or (t_activity.activity_cancelled) Is Null) AND (([t_activity_brand1].[price_off_diageo_invoice])=True) AND (([t_activity_brand1].[activity_brand_cancelled])=False Or ([t_activity_brand1].[activity_brand_cancelled]) Is Null));

Many Thanks!

shovan
Hi Shovan,

I see your previous thread post was about SQL server too. It seems to me you have an ongoing project to convert an MDB fileserver application to SQL server backend and convert the frontend to an Access ADP Project file not just this query am I correct?

There are several elements of that SQL statement that will not work in SQL server the VBA NZ wrapper function is one of them where you could convert using either coalesce or case expression.

The useage of Access's default EXPR in aliasing column data in my view is pretty useless, it doesn't on the face of it visually 'mean' anything if presented as a header for a column of data in a matrixed display, you really need meaningful names there.

The VBA function whatever it does will have logic in it that needs to be replicated on the server. (whether that maps to a user defined function UDF in SQL Server or worked out within the stored procedure or otherwise via amended SQL remains to be seen. From what I see there it does no more than provide some sort of value for the WHERE clause argument of the SQL thus far)

To convert this properly would require prefixing the relevant tables with the OWNER (dbo) predicate to eradicate conflicts. (Its not always necessary but it is good practice in a multi user environment together with a host of other things not least of which is passing parameters to the 'stored procedure' you require evidently currently contained in the where clause of your posted SQL)

When I convert or create applications in SQL Server I ensure the dog (sql server woof) wags the tail and not the other way round. All of any SQL should sit on top of properly revised table structures having a standard naming convention and with datatypes to suit. Some datatypes and resultant values in Access are different in SQL Server. Inevitably I end up re-writing whole blocks of stuff that hitherto worked perfectly well in Access but which now needs wholesale amendment to suit the new more powerful backend environment properly!

To do it 'properly' rather than peacemeal requires an understanding of what you have there derived from a workable knowledge of your table structure keys, constraints, indexes relationships in other words a full scripted out text file of this, so that it could be replicated and tested. I would not be comfortable with saying "yeaaaah simply paste the SQL into a stored procedure and hope for the best" not good advice for futureproofing in my view.

On the face of it, the posted SQL is simply a single table joined to two others having restrictive crtieria centering on the VBA function return value together with a few boolean true or false values nothing too elaborate.

I am mindful of moving this to the SQL server forum, but will leave it here for the time being because of the Access ADP Project aspect to this (unless admins insist it be moved in which case I will).

Are you able to post your SQL Server table structure as a scripted out text file and also the contents of the VBA function so that we can see what it is doing, in pretty much the same way functionally, as you see? I think that needs dealing with first before any ADP frontend

Regards

Jim :)
Dec 13 '07 #2

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

Similar topics

5
by: mmm, Pie | last post by:
I never ever thought about this, but recently I made a query in access so I can make a customer mailing list based on relational information and it was so easy to make the query and join tables and...
3
by: William Buchanan | last post by:
Hi I have the following stored proc in interbase (which might contain errors - i'm doing it off the top of my head), which I would like to convert into oracle. Can you help? What I want back is...
29
by: Mark B | last post by:
We have an Access app (quite big) at www.orbisoft.com/download. We have had requests by potential users to have it converted to an SQL version for them since there corporate policy excludes them...
15
by: brettclare | last post by:
I have linked a large SQL Server table to Access, however 'only' 2,195,439 records are shown and are available to query. Can I increase the size (cache??)/number of records showing in Access? ...
4
by: Tarun Mistry | last post by:
Hi all, I have posted this in both the c# and asp.net groups as it applies to both (apologies if it breaks some group rules). I am making a web app in asp.net using c#. This is the first fully OO...
2
by: shovan mohanty | last post by:
Hi, can anybody convert below access NZ()function(Access Queries) to stored procedure: nz(!*!,0) AS po_x_nb_bt_planned Thanks! shovan
2
by: rahuldev999 | last post by:
Hi Can anyone please convert the below access query to the equivalent stored procedure.No problem with the IIF() function but the condition in the "where" clause making problem.so please put some...
2
by: acw | last post by:
On a SQL Server 2000 db I would like to setup a stored procedure that accesses couple tables and runs the extended stored procedure xp..cmdshell. The goal is to grant users with limited privileges...
13
by: Neil | last post by:
I'm running an update query in SQL 7 from QA, and it runs forever. Has been running for 20 minutes so far! The query is quite simple: update a single field in a table, based on a join with another...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...

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.