DECLARE SYNTAX

DECLARE SYNTAX

am 26.06.2006 23:42:17 von harpalshergill

i have a problem in following code can anyone help?

declare @x int
set @x = (SELECT max(ixBugEvent) FROM bugevent)

UPDATE bugevent
SET ixAttachment = (SELECT max(ixAttachment) FROM attachment),
ixBug = (SELECT max(ixBug) FROM bug)
WHERE ixBugEvent = @x;

Re: DECLARE SYNTAX

am 27.06.2006 10:31:12 von Thomas Rachel

harpalshergill@gmail.com wrote:

> i have a problem in following code can anyone help?

No, as long as you don't tell us which problem you have.

> declare @x int

This doesn't seem MySQL (at least not < 5.0), but the remainder seems ok to
me...


Thomas

Re: DECLARE SYNTAX

am 27.06.2006 11:44:29 von Axel Schwenke

harpalshergill@gmail.com wrote:
^^^^^^^^^^^^^^
Who?

> i have a problem in following code can anyone help?

I guess with "problem" you mean the syntax errors you will get from
MySQL for the code below?

You can help yourself by RTFM:
http://dev.mysql.com/doc/refman/5.0/en/variables-in-stored-p rocedures.html

> declare @x int
> set @x = (SELECT max(ixBugEvent) FROM bugevent)

DECLARE x INT;
SELECT ... INTO x ... ;

> UPDATE bugevent
> SET ixAttachment = (SELECT max(ixAttachment) FROM attachment),
> ixBug = (SELECT max(ixBug) FROM bug)
> WHERE ixBugEvent = @x;

SELECT ... INTO max1 FROM attachment;
SELECT ... INTO max2 FROM bug;
UPDATE bugevent SET ixAttachment=max1, ixBug=max2 ... ;


*BUT* selecting max() from one table and inserting this value in
another table may create race conditions. Probably you want to wrap
this in a transaction.


XL