Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6723707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:36:04+00:00 2026-05-26T09:36:04+00:00

im having problems creating a function that must return the amount of goals of

  • 0

im having problems creating a function that must return the amount of goals of a team as a home and away
First it sums all local goals, and then it sums all visitor goals, and saves into variables, but the problem is, i want to know what can i do if there is NO data, i mean, what can i do when it returns NULL, i tried with IF ELSE but still not working, here is the code:

CREATE DEFINER=`root`@`localhost` FUNCTION `vgoles`(`veq` int) RETURNS int(11)
BEGIN
#Routine body goes here...
DECLARE vgloc INT;
DECLARE vgvis INT;
DECLARE vgoles INT;
SELECT SUM(gloc) INTO @vgloc FROM partidos WHERE eqloc=@veq;
SELECT SUM(gvis) INTO @vgvis FROM partidos WHERE eqvis=@veq;
IF @vgloc = NULL THEN
SET @vgloc = 0;
END IF;
IF @vgvis = NULL THEN
SET @vgvis = 0;
END IF;
SET @vgoles=@vgloc+@vgvis;
RETURN @vgoles;
END

Thanks and have a nice day

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T09:36:05+00:00Added an answer on May 26, 2026 at 9:36 am

    The IF @vgloc = NULL THEN does not work as you expect because you can’t check NULL with equality (=). NULL is a special value that is not equal to anything, not even to itself.

    SELECT (3 = NULL)          --yields--> NULL
    SELECT NOT (3 = NULL)      --yields--> NULL
    SELECT (NULL = NULL)       --yields--> NULL
    SELECT (NULL <> NULL)      --yields--> NULL
    SELECT (NULL IS NULL)      --yields--> TRUE  
    

    To check for NULL value, you need: IF @vgloc IS NULL THEN.

    But you can also use COALESCE() function for further simplicity:

    SELECT COALESCE(SUM(gloc),0) INTO @vgloc FROM partidos WHERE eqloc=@veq;
    SELECT COALESCE(SUM(gvis),0) INTO @vgvis FROM partidos WHERE eqvis=@veq;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're having a significant number of problems creating a bulk upload function for our
I am having some problems creating a query that gives me the average of
I'm having problems with some dynamic elements that I'm creating with Jquery. for(var i
My function is having problems creating and copying the contents to the new directory
I have been having problems with creating a download list of files for a
I'm creating a website for my church and I'm having problems making it display
I seem to be having some problems creating a jquery plugin. I am testing
Having a few problems with Timers within a service on Win2k3... Basically, creating a
I am having problems creating a managed class with namespace in C++/CLI. I would
I'm having a problem creating an function similar to the nub function. I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.