Click here to get back home

Creating FUNCTIONS/PROCEEDURES

 HomeNewsGroups | Search | About
 mailing.database.mysql    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Creating FUNCTIONS/PROCEEDURES Cerebral Believer 09-16-2006
Get Chitika Premium
Posted by Cerebral Believer on September 16, 2006, 5:00 pm
Please log in for more thread options
Hi everybody,

I have the following statement:

SELECT SUM(`Quantity Ordered`) FROM `Sales Detail Information` WHERE
`Catalogue Number` = "FBDCD008";

I can run this as a query in the SQL window, and it works fine.

How could I turn this query into a FUNCTION or perhaps better still a
PROCEEDURE? I am not sure if FUNCTIONS can reference tables...

I am using phpadmin 2.7.0, and My SQL 5.0.15. I would like to get the
statement registered as a FUNCTION/PROCEEDURE so that I can so that I can
select it from the "Function" selector on the "Insert" sub-tab in
myphpadmin. I hope this will enable the column to always hold the current
value for Quantity Sold (the sum total of "Quantity Ordered"). This is the
only way I can think of achieving this goal, unless someone has another
idea?

Any thoughts on this?

Regards,
C.B.



Posted by NC on September 16, 2006, 5:50 pm
Please log in for more thread options
Cerebral Believer wrote:
>
> I have the following statement:
>
> SELECT SUM(`Quantity Ordered`)
> FROM `Sales Detail Information` WHERE
> `Catalogue Number` = "FBDCD008";
>
> I can run this as a query in the SQL window, and it works fine.
>
> How could I turn this query into a FUNCTION or perhaps
> better still a PROCEEDURE? I am not sure if FUNCTIONS
> can reference tables...

Read MySQL documentation:

http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html

Cheers,
NC


Posted by Cerebral Believer on September 17, 2006, 9:37 am
Please log in for more thread options

> Cerebral Believer wrote:
>>
>> I have the following statement:
>>
>> SELECT SUM(`Quantity Ordered`)
>> FROM `Sales Detail Information` WHERE
>> `Catalogue Number` = "FBDCD008";
>>
>> I can run this as a query in the SQL window, and it works fine.
>>
>> How could I turn this query into a FUNCTION or perhaps
>> better still a PROCEEDURE? I am not sure if FUNCTIONS
>> can reference tables...
>
> Read MySQL documentation:
>
> http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html

Thanks, I keep getting Error #1064, but the same syntax works fine for a
simple query.

CREATE FUNCTION Sum_001R RETURNS INT
SELECT SUM(`Quantity Ordered`) FROM `Sales Detail Information`
WHERE`Catalogue Number` = "FBDCD008";

I am perplexed.

Regards,
C.B.



Posted by Cerebral Believer on September 17, 2006, 10:59 am
Please log in for more thread options

>
>> Cerebral Believer wrote:
>>>
>>> I have the following statement:
>>>
>>> SELECT SUM(`Quantity Ordered`)
>>> FROM `Sales Detail Information` WHERE
>>> `Catalogue Number` = "FBDCD008";
>>>
>>> I can run this as a query in the SQL window, and it works fine.
>>>
>>> How could I turn this query into a FUNCTION or perhaps
>>> better still a PROCEEDURE? I am not sure if FUNCTIONS
>>> can reference tables...
>>
>> Read MySQL documentation:
>>
>> http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html
>
> Thanks, I keep getting Error #1064, but the same syntax works fine for a
> simple query.
>
> CREATE FUNCTION Sum_001R RETURNS INT
> SELECT SUM(`Quantity Ordered`) FROM `Sales Detail Information`
> WHERE`Catalogue Number` = "FBDCD008";
>
> I am perplexed.

OK,

I found the answer, again quite simple, but requiring back-tick quotes
(which I had not put round the proceedure name), which is not specified on
the MySQL website, neither in the reference material or the examples. So
this works:

CREATE PROCEDURE `008_sales`()
SELECT SUM(`Quantity Ordered`) FROM `Sales Detail Information` WHERE
`Catalogue Number` = "FBDCD008";

Anyone know how I can get a column to automatically run that procedure? Is
that even possible?

Regards,
C.B.



Similar ThreadsPosted
Creating user error June 25, 2005, 2:56 pm
Creating an unique record id ?? October 9, 2005, 1:15 pm
Creating queries for one-to-many tables December 11, 2005, 10:02 pm
creating foreign fields January 22, 2006, 12:25 pm
Creating an A to Z list from query February 9, 2006, 9:56 am
Creating my own Data dictionary April 21, 2006, 9:48 pm
creating a url distribution report June 23, 2006, 7:26 pm
creating table for rails June 20, 2007, 3:41 am
Creating a hyperlink to a specific record January 9, 2006, 2:05 pm
Creating ordered lists that ignore the word 'The' at the start of phrases December 22, 2005, 9:55 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap