1

I have a function in mysql like below:

DELIMITER $$ 

CREATE DEFINER=root@localhost FUNCTION fnGetDropDownValue(
    itemValue varchar(300), 
    DropDownId int, 
    CId int
) RETURNS int(11)
BEGIN
    DECLARE listId int;
    SELECT ListID into listId FROM DropDownListValues WHERE LOWER(ListValue) = LOWER(itemValue) AND DropDownListID = DropDownId AND (ClientId = 0 OR ClientId = CId);
    RETURN listId;
END$$


But it always returns Null values when I use
SELECT fnGetDropDownValue('General', 24, 18); I don't know what I am doing wrong :(

5
  • Have you checked your error log? What errors do you get? What steps have you taken to troubleshoot this? Commented Mar 1, 2013 at 16:18
  • Have you tried your query direct in sheel? Does it return it value? Commented Mar 1, 2013 at 16:21
  • I used to check executing select query in a separate window and it gives result Commented Mar 1, 2013 at 16:21
  • What happens if you replace the select query in the function with a simple SELECT 5 INTO listId? Does it still give you NULL? Commented Mar 1, 2013 at 16:25
  • Thanks for the help Alanyst i noticed in windows it as case insensitive. I changed variable listId to listId1 and now it works. Commented Mar 4, 2013 at 8:25

1 Answer 1

1

After having the case sensitive issue with mysql columns I used to have variable names to start with _ to avoid it messing with column names. Now the stored procedure looks like this:

DELIMITER $$ 

CREATE DEFINER=root@localhost FUNCTION fnGetDropDownValue(
    itemValue varchar(300), 
    DropDownId int, 
    CId int
) RETURNS int(11)
BEGIN
    DECLARE _listId int;
    SELECT ListID into _listId FROM DropDownListValues WHERE LOWER(ListValue) = LOWER(itemValue) 
        AND DropDownListID = DropDownId AND (ClientId = 0 OR ClientId = CId);
    RETURN _listId;
END$$

This way it will work on any platform and it may be useful for others.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.