Unix Technical Forum

DECLARE SYNTAX

This is a discussion on DECLARE SYNTAX within the MySQL forums, part of the Database Server Software category; --> declare @x int set @x = (SELECT max(ixBugEvent) FROM bugevent) UPDATE bugevent SET ixAttachment = (SELECT max(ixAttachment) FROM attachment), ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 08:51 AM
harpalshergill@gmail.com
 
Posts: n/a
Default DECLARE SYNTAX

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;

i have a problem in the given code, can anyone help me to tell what's
wrong here?

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 08:51 AM
Paul Lautman
 
Posts: n/a
Default Re: DECLARE SYNTAX

harpalshergill@gmail.com wrote:
> 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;
>
> i have a problem in the given code, can anyone help me to tell what's
> wrong here?


Would you care to tell us what problem you are seeing?


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 08:51 AM
Kees Nuyt
 
Posts: n/a
Default Re: DECLARE SYNTAX

On 26 Jun 2006 14:39:09 -0700, harpalshergill@gmail.com wrote:

>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;
>
>i have a problem in the given code, can anyone help me to tell what's
>wrong here?


You left out the semicolons after the first two statements.
--
( Kees
)
c[_] Giving power and money to government is like giving
whiskey and car-keys to teenage boys. (PJ O'Rourke) (#181)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 08:52 AM
getziiiiiiiiiii
 
Posts: n/a
Default Re: DECLARE SYNTAX

i am getting a syntax error for the code which posted before. i am
using MySQL 4.0 and this is the error i am getting:
_message "#42000You have an error in your SQL syntax; check the manual
that corresponds to your MySQL server version for the right syntax to
use near 'DECLARE @bugrtr int SET @bugrtr = (SELECT max(ixBugEvent)
FROM bugevent);UPDATE ' at line 1" string

I also tried it with the ';' at the end of secound statement, but it
still the same.
any thing else u want to know??


Paul Lautman wrote:
> harpalshergill@gmail.com wrote:
> > 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;
> >
> > i have a problem in the given code, can anyone help me to tell what's
> > wrong here?

>
> Would you care to tell us what problem you are seeing?


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 08:52 AM
Paul Lautman
 
Posts: n/a
Default Re: DECLARE SYNTAX

getziiiiiiiiiii wrote:
> i am getting a syntax error for the code which posted before. i am
> using MySQL 4.0 and this is the error i am getting:
> _message "#42000You have an error in your SQL syntax; check the manual
> that corresponds to your MySQL server version for the right syntax to
> use near 'DECLARE @bugrtr int SET @bugrtr = (SELECT max(ixBugEvent)
> FROM bugevent);UPDATE ' at line 1" string
>
> I also tried it with the ';' at the end of secound statement, but it
> still the same.
> any thing else u want to know??
>

I think Kees was suggesting that you needed a semicolon after each of the
first two statements.
I hope that works for you, because I really don't like your attitude so
you'll have to hope that someone else will help you after this.


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 08:52 AM
Kees Nuyt
 
Posts: n/a
Default Re: DECLARE SYNTAX

On 27 Jun 2006 06:22:53 -0700, "getziiiiiiiiiii"
<harpalshergill@gmail.com> wrote:

>i am getting a syntax error for the code which posted before. i am
>using MySQL 4.0 and this is the error i am getting:
> _message "#42000You have an error in your SQL syntax; check the manual
>that corresponds to your MySQL server version for the right syntax to
>use near 'DECLARE @bugrtr int SET @bugrtr = (SELECT max(ixBugEvent)
>FROM bugevent);UPDATE ' at line 1" string
>
>I also tried it with the ';' at the end of secound statement, but it
>still the same.
>any thing else u want to know??


Please read the suggestions more carefully next time: you still
need a semicolon after the DECLARE statement.
If that doesn't help, i'm out of options and you're on your own.
Good luck.
--
( Kees
)
c[_] Nostalgia. Sure ain't what it used to be.... (#26)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-28-2008, 08:52 AM
Bill Karwin
 
Posts: n/a
Default Re: DECLARE SYNTAX

harpalshergill@gmail.com wrote:
> declare @x int


Is this within the body of a stored procedure? The manual page
http://dev.mysql.com/doc/refman/5.0/en/declare.html says:

"DECLARE is allowed only inside a BEGIN ... END compound statement and
must be at its start, before any other statements."

That means it works only inside stored procedures or stored functions.

If you're trying to do this declare statement outside the definition of
a stored routine, e.g. simply at a mysql CLI prompt, then it doesn't work.

Regards,
Bill K.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-28-2008, 08:52 AM
Dikkie Dik
 
Posts: n/a
Default Re: DECLARE SYNTAX

This is SQL Server code, I assume. You don't have to DECLARE anything in
loose MySQL scripts. Also, the variables live as long as the session
(the connection).

Best regards,
Willem Bogaerts

harpalshergill@gmail.com wrote:
> 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;
>
> i have a problem in the given code, can anyone help me to tell what's
> wrong here?
>

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:08 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com