SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Stored Procedure IF query

    Could someone please help me understand what is wrong with this query?

    ------------------------------------------------------------------------------DELIMITER $$

    CREATE DEFINER=`root`@`localhost` PROCEDURE `spAddNewCountry`(IN countryTag TEXT, IN countryName TEXT, IN langTag TEXT)
    BEGIN
    DECLARE countryId INT;
    SET countryId = -1;
    SELECT Country_Id INTO countryId FROM tbl_country WHERE Country_Tag = countryTag;
    IF (countryId = -1) THEN
    INSERT INTO tbl_country (Country_Id, Country_Tag)
    SELECT NULL, countryTag;
    END IF;
    SELECT Country_Id INTO countryId FROM tbl_country WHERE Country_Tag = countryTag;

    DECLARE translationId INT;
    SET translationId = -1;
    SELECT Translation_Id INTO translationId FROM tbl_translation WHERE Translation_Identification_Tag = countryTag);
    IF (translationId = -1) THEN
    BEGIN
    INSERT INTO tbl_translations (Translation_Id, Translation_Identification_Tag, Data_Language_Id, Translation_Value)
    SELECT NULL, countryTag, (SELECT Language_Id FROM tbl_language WHERE Language_Tag = langTag), countryName;
    END;
    END $$
    ------------------------------------------------------------------------------

    Thanks
    Shahar

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,340
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    you have an unbalanced parenthesis

    you have a malformed SELECT statement

    you used END where you shoulda used END IF
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Member
    Join Date
    Dec 2011
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks - The issue was at the end the fact that I had a declare statement in the middle of the query.


    Quote Originally Posted by r937 View Post
    you have an unbalanced parenthesis

    you have a malformed SELECT statement

    you used END where you shoulda used END IF


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •