Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Syntax error ?

Status
Not open for further replies.

Joshua42

Programmer
Dec 3, 2003
1
DE
Hi,

I am new to MySQL. Up to now I never needed Transact SQL, but now I have learned it can be useful :). MySQL rejects the message Syntax error in insert. Any ideas what I did wrong?

Thanks in advance,
Josh

Here is my Code:

BEGIN
DECLARE @right_most_sibling INTEGER;
SET @right_most_sibling = SELECT rgt FROM personnel WHERE
emp ='Joshua';

UPDATE personnel SET lft = CASE WHEN lft >
@right_most_sibling
THEN lft+2
ELSE lft END,
rgt =CASE WHEN rgt >= @right_most_sibling
THEN rgt +2
ELSE rgt END
WHERE rgt >= @right_most_sibling

INSERT INTO personnel (emp, lft, rgt)
VALUES ('New GUY', @right_most_sibling,
(@right_most_sibling +1))
END;
 
MySQL doesn't use BEGIN and END. It uses START TRANSACTION and COMMIT. (
MySQL also does not support transactions with all table types. You will have to use the InnoDB or BDB table types. (
MySQL doesn't use DECLARE for user-defined variables. It uses SET. (
IF, THEN, ELSE are not block-operators in MySQL. You might want to take a look at the IF() function. (
Multiple statements in a block are terminated by semicolons in MySQL.


Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top