{"id":7259,"date":"2014-06-03T23:26:13","date_gmt":"2014-06-03T23:26:13","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/06\/03\/unexpected-if-in-mysql-procedure-collection-of-common-programming-errors\/"},"modified":"2014-06-03T23:26:13","modified_gmt":"2014-06-03T23:26:13","slug":"unexpected-if-in-mysql-procedure-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/06\/03\/unexpected-if-in-mysql-procedure-collection-of-common-programming-errors\/","title":{"rendered":"Unexpected IF in MySQL procedure-Collection of common programming errors"},"content":{"rendered":"<ul>\n<li><img decoding=\"async\" src=\"http:\/\/www.gravatar.com\/avatar\/84dc26c6486551ba2b477b8ec35e90dc?s=32&amp;d=identicon&amp;r=PG\" \/><br \/>\nOMG Ponies<\/p>\n<p>Can anyone tell me what is wrong with the following procedure? MySQL says it is an &#8216;unexpected IF&#8217;. I looked up the syntax for an IF statement and I simply don&#8217;t see what the problem is.<\/p>\n<pre><code>create procedure spInsertAccount\n(\nAccountID INT,\nInUse bit,\nIsBanned bit,\nIsPremium bit,\nIsGolden bit,\nUsername VARCHAR(20),\nPassword VARCHAR(20),\nEmail VARCHAR(65),\nLoggedInID INT,\nCreateDate DATETIME\n)\n\n    SET @accountExists = (SELECT * FROM Accounts WHERE AccountID = @AccountID);\n\n    IF (accountExists &gt; 0) THEN\n\n   INSERT IGNORE INTO Accounts(AccountID, InUse, IsBanned, IsPremium, IsGolden, Username, Password,\n                        Email, LoggedInID, CreateDate\n                       )\n        values (@AccountID, @InUse, @IsBanned, @IsPremium, @IsGolden, @Username, @Password,\n               @Email, @LoggedInID, @CreateDate);\n        #where NOT EXISTS( SELECT * FROM Accounts WHERE AccountID = @AccountID);\n\n    END IF;\n<\/code><\/pre>\n<\/li>\n<li><img decoding=\"async\" src=\"http:\/\/i.stack.imgur.com\/trXvh.jpg?s=32&amp;g=1\" \/><br \/>\nthemis<\/p>\n<p>Try this instead<\/p>\n<p>Also check out here http:\/\/net.tutsplus.com\/tutorials\/an-introduction-to-stored-procedures\/<\/p>\n<pre><code>DELIMITER \/\/  \ncreate procedure `spInsertAccount`\n(\nIN AccountID INT,\nIN InUse bit,\nIN IsBanned bit,\nIN IsPremium bit,\nIN IsGolden bit,\nIN Username VARCHAR(20),\nIN Password VARCHAR(20),\nIN Email VARCHAR(65),\nIN LoggedInID INT,\nIN CreateDate DATETIME\n)\nBEGIN\n    SET @accountExists = (SELECT * FROM Accounts WHERE AccountID = @AccountID);\n\n    if (accountExists &gt; 0) THEN \n        INSERT IGNORE INTO Accounts(AccountID, InUse, IsBanned, IsPremium, IsGolden, Username, Password,Email, LoggedInID, CreateDate)\n        values (@AccountID, @InUse, @IsBanned, @IsPremium, @IsGolden, @Username, @Password,\n               @Email, @LoggedInID, @CreateDate);\n        #where NOT EXISTS( SELECT * FROM Accounts WHERE AccountID = @AccountID);\n\n    END IF;\nEND \/\/\n<\/code><\/pre>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>OMG Ponies Can anyone tell me what is wrong with the following procedure? MySQL says it is an &#8216;unexpected IF&#8217;. I looked up the syntax for an IF statement and I simply don&#8217;t see what the problem is. create procedure spInsertAccount ( AccountID INT, InUse bit, IsBanned bit, IsPremium bit, IsGolden bit, Username VARCHAR(20), Password [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7259","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7259","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=7259"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/7259\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=7259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=7259"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=7259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}