MySQL Forums
Forum List  »  General

Count in function does not work WHY ?
Posted by: P Farrell
Date: June 15, 2014 04:32AM

Simple..the table has groups with a number of properties each with a date for every day of the year

This statement works fine

SELECT count(*)
FROM allbookings
where ( bookingdate between '2014-06-13' and '2014-06-20'
and groupid='LP4253'
and propid=9 ) ;

The answer is 8

when I put this in a function the answer is 336 !!


CREATE DEFINER=`XXXXXXXXXXX`@`%` FUNCTION `getrpropertycount`
(groupid varchar(45),
propid INT,
startdate Date,
enddate Date
) RETURNS int(11)
BEGIN
DECLARE pcount INT ;
set pcount=0;

SELECT count(*) into pcount
FROM allbookings
where
( bookingdate between '2014-06-13' and '2014-06-20'
and groupid='LP4253'
and propid=9 ) ;


RETURN pcount;

END



I checked this is the same as

SELECT count(*)
FROM allbookings
where ( bookingdate between '2014-06-13' and '2014-06-20') ;

ie every time I use a date comparisson ALL the other statements are ignored

Why ?.. what stupid mistake am I making

Options: ReplyQuote


Subject
Written By
Posted
Count in function does not work WHY ?
June 15, 2014 04:32AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.