what is wrong woth this statement?

what is wrong woth this statement?

am 19.10.2004 18:45:30 von Josh Howe

------_=_NextPart_001_01C4B5FB.336BE306
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

if (select count(*) from z_mail_systems > 0) then [insert statement]
endif;

=20

How do I do this kind of conditional insert? Thanks.=20


------_=_NextPart_001_01C4B5FB.336BE306--

Re: what is wrong woth this statement?

am 19.10.2004 19:01:25 von SGreen

--=_alternative 005DB37985256F32_=
Content-Type: text/plain; charset="US-ASCII"

First, assume you want to insert records, then only insert the records you
want to add to the destination table.

INSERT destinationtablename ()
SELECT
FROM sourcetablename
WHERE ....

Basically if you can build a query to return the records you want to
INSERT, you can stick an INSERT clause to the front of it to make those
records end up in some table.

http://dev.mysql.com/doc/mysql/en/INSERT_SELECT.html

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine


"Josh Howe" wrote on 10/19/2004 12:45:30 PM:

> if (select count(*) from z_mail_systems > 0) then [insert statement]
> endif;
>
>
>
> How do I do this kind of conditional insert? Thanks.
>

--=_alternative 005DB37985256F32_=--

Re: what is wrong woth this statement?

am 20.10.2004 05:38:03 von Leonardus Setiabudi

i didnt fully catch you...
is this the kind of query statement you want?

INSERT INTO some_other_table
SELECT
some_field_list
FROM z_mail_systems
HAVING COUNT(any_field)>0


On Tue, 19 Oct 2004 12:45:30 -0400, Josh Howe wrote:
> if (select count(*) from z_mail_systems > 0) then [insert statement]
> endif;
>
> How do I do this kind of conditional insert? Thanks.
>
>

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql@m.gmane.org

RE: what is wrong woth this statement?

am 27.10.2004 21:15:11 von Josh Howe

Sorry, I don't think I was very clear. I'm asking a more generic
question about control flow expressions. I want to run a sql statement
but only if a certain condition is met, namely if a particular record
exists in a table. I want to do it all in a single mysql statement, like
so:

If ([record exists]) then
Do some sql
End If

How can I do this? Thanks.=20


-----Original Message-----
From: Leo [mailto:leonardus@gmail.com]=20
Sent: Tuesday, October 19, 2004 11:38 PM
To: Josh Howe
Cc: mysql@lists.mysql.com
Subject: Re: what is wrong woth this statement?

i didnt fully catch you...
is this the kind of query statement you want?

INSERT INTO some_other_table
SELECT
some_field_list
FROM z_mail_systems
HAVING COUNT(any_field)>0


On Tue, 19 Oct 2004 12:45:30 -0400, Josh Howe wrote:
> if (select count(*) from z_mail_systems > 0) then [insert statement]
> endif;
>=20
> How do I do this kind of conditional insert? Thanks.
>=20
>

--=20
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:
http://lists.mysql.com/mysql?unsub=3DWojciech.Matulewicz@nes tle.pl




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgcdmg-mysql@m.gmane.org

RE: what is wrong woth this statement?

am 27.10.2004 21:27:20 von Josh Howe

Thanks, but I tried that and it doesn't seem to work any better than an
"if" statement. Have you tried it? Maybe I am doing something wrong. If
you could post some working code that would be awesome.


-----Original Message-----
From: sol beach [mailto:sol.beach@gmail.com]=20
Sent: Wednesday, October 27, 2004 3:25 PM
To: Josh Howe
Subject: Re: what is wrong woth this statement?

> How can I do this?=20
By using the CASE staement?

On Wed, 27 Oct 2004 15:15:11 -0400, Josh Howe wrote:
> Sorry, I don't think I was very clear. I'm asking a more generic
> question about control flow expressions. I want to run a sql statement
> but only if a certain condition is met, namely if a particular record
> exists in a table. I want to do it all in a single mysql statement,
like
> so:
>=20
> If ([record exists]) then
> Do some sql
> End If
>=20
> How can I do this? Thanks.
>=20
> -----Original Message-----
> From: Leo [mailto:leonardus@gmail.com]
> Sent: Tuesday, October 19, 2004 11:38 PM
> To: Josh Howe
> Cc: mysql@lists.mysql.com
> Subject: Re: what is wrong woth this statement?
>=20
> i didnt fully catch you...
> is this the kind of query statement you want?
>=20
> INSERT INTO some_other_table
> SELECT
> some_field_list
> FROM z_mail_systems
> HAVING COUNT(any_field)>0
>=20
> On Tue, 19 Oct 2004 12:45:30 -0400, Josh Howe wrote:
> > if (select count(*) from z_mail_systems > 0) then [insert statement]
> > endif;
> >
> > How do I do this kind of conditional insert? Thanks.
> >
> >
>=20
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> http://lists.mysql.com/mysql?unsub=3DWojciech.Matulewicz@nes tle.pl
>=20
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
http://lists.mysql.com/mysql?unsub=3Dsol.beach@gmail.com
>=20
>



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgcdmg-mysql@m.gmane.org

RE: what is wrong woth this statement?

am 27.10.2004 21:29:59 von SGreen

--=_alternative 006B4E7085256F3A_=
Content-Type: text/plain; charset="US-ASCII"

Nearly all of the T-SQL style procedural statements (IF... BEGIN... END,
WHILE...WEND, cursors, etc.) are not currently available in MySQL.
Procedural scripts , like the one you propose, will be available in Stored
Procedures (new to MySQL 5.0+). I haven't tested that version yet, so I
can't tell you if it will support a statement like yours outside of a
stored procedure (as a stand-alone statement).

As of right now, you still need to make control-of-flow decisions in your
programming language not your SQL statements. Sorry.

Depending on what you are trying to do, there may be valid MySQL SQL
statement or sequence of statements that will duplicate the behavior of
the decision you are trying to make. Can you be very specific about what
action(s) you want your statement to make?

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine

"Josh Howe" wrote on 10/27/2004 03:15:11 PM:

> Sorry, I don't think I was very clear. I'm asking a more generic
> question about control flow expressions. I want to run a sql statement
> but only if a certain condition is met, namely if a particular record
> exists in a table. I want to do it all in a single mysql statement, like
> so:
>
> If ([record exists]) then
> Do some sql
> End If
>
> How can I do this? Thanks.
>
>
> -----Original Message-----
> From: Leo [mailto:leonardus@gmail.com]
> Sent: Tuesday, October 19, 2004 11:38 PM
> To: Josh Howe
> Cc: mysql@lists.mysql.com
> Subject: Re: what is wrong woth this statement?
>
> i didnt fully catch you...
> is this the kind of query statement you want?
>
> INSERT INTO some_other_table
> SELECT
> some_field_list
> FROM z_mail_systems
> HAVING COUNT(any_field)>0
>
>
> On Tue, 19 Oct 2004 12:45:30 -0400, Josh Howe wrote:
> > if (select count(*) from z_mail_systems > 0) then [insert statement]
> > endif;
> >
> > How do I do this kind of conditional insert? Thanks.
> >
> >
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> http://lists.mysql.com/mysql?unsub=Wojciech.Matulewicz@nestl e.pl
>
>
>
>
> --
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe: http://lists.mysql.com/mysql?unsub=sgreen@unimin.com
>

--=_alternative 006B4E7085256F3A_=--

Re: what is wrong woth this statement?

am 27.10.2004 21:48:37 von Michael Stassen

Josh,

You cannot do this in mysql, as there is no such construct.

Perhaps you've been misled by the title of section 13.2, "Control Flow
Functions" .
Despite the name, mysql has no control flow functions. What it has are
functions whose return values are conditional.

There are some cases where

IF (something) THEN (do something)

can be rewritten into valid SQL, but in general the solution is to do this
in your application code.

Michael

Josh Howe wrote:

> Sorry, I don't think I was very clear. I'm asking a more generic
> question about control flow expressions. I want to run a sql statement
> but only if a certain condition is met, namely if a particular record
> exists in a table. I want to do it all in a single mysql statement, like
> so:
>
> If ([record exists]) then
> Do some sql
> End If
>
> How can I do this? Thanks.
>
>
> -----Original Message-----
> From: Leo [mailto:leonardus@gmail.com]
> Sent: Tuesday, October 19, 2004 11:38 PM
> To: Josh Howe
> Cc: mysql@lists.mysql.com
> Subject: Re: what is wrong woth this statement?
>
> i didnt fully catch you...
> is this the kind of query statement you want?
>
> INSERT INTO some_other_table
> SELECT
> some_field_list
> FROM z_mail_systems
> HAVING COUNT(any_field)>0
>
>
> On Tue, 19 Oct 2004 12:45:30 -0400, Josh Howe wrote:
>
>>if (select count(*) from z_mail_systems > 0) then [insert statement]
>>endif;
>>
>>How do I do this kind of conditional insert? Thanks.
>>
>>
>
>

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql@m.gmane.org

RE: what is wrong woth this statement?

am 27.10.2004 21:52:45 von Josh Howe

------_=_NextPart_001_01C4BC5E.AC28FBB2
Content-Type: text/plain;
charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

=20

Thanks Shawn. Basically, our deployment mechanism involves applying sql
change scripts as part of the build process. I created this simple shell
script:

=20

host=3D"$1"

user=3D"$2"

pwd=3D"$3"

=20

mysql -u$user -p$pwd -h$host -f sinu_com <<_EOF_

=20

#Put the scripts to execute here:

\. z_worklog_alter.sql

\. z_companies_alter.sql

=20

quit

_EOF_

=20

=20

I'd like to be able to run this script multiple times against the same
db without corrupting the data or structure, and without generating
error messages that don't indicate a real problem with one of the
scripts (e.g. "that column already exists"). To this end, I want to put
code in all of the ".sql" files so that it only executes once. E.g. if
the sql is:

=20

Insert into users values ("myemail","mypassword")

=20

I would want some thing like this:

=20

If(not exists(select * from users where username=3D"myemail"), Insert =
into
users values ("myemail","mypassword"))

=20

=20

I think I can protect against bad data with the proper keys and unique
indexes. I'm not sure about this though. But even if I can protect the
db from corruption, I will still get a bunch of primary key violations
and such, and this will make it harder to extract the actual errors
(e.g. syntax errors in the sql) when I run the script.

=20

So that's why I want to do this. I hope that made sense. I guess that
rather than trying to execute each script directly I can execute each
via an intermediate perl script that updates the db to indicate which
change scripts have been applied. That's more complex though. Any ideas
would be greatly appreciated. Thanks!=20

=20

=20

=20

=20

=20

________________________________

From: SGreen@unimin.com [mailto:SGreen@unimin.com]=20
Sent: Wednesday, October 27, 2004 3:30 PM
To: Josh Howe
Cc: Leo; mysql@lists.mysql.com
Subject: RE: what is wrong woth this statement?

=20


Nearly all of the T-SQL style procedural statements (IF... BEGIN... END,
WHILE...WEND, cursors, etc.) are not currently available in MySQL.
Procedural scripts , like the one you propose, will be available in
Stored Procedures (new to MySQL 5.0+). I haven't tested that version
yet, so I can't tell you if it will support a statement like yours
outside of a stored procedure (as a stand-alone statement).=20

As of right now, you still need to make control-of-flow decisions in
your programming language not your SQL statements. Sorry.=20

Depending on what you are trying to do, there may be valid MySQL SQL
statement or sequence of statements that will duplicate the behavior of
the decision you are trying to make. Can you be very specific about what
action(s) you want your statement to make?=20

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine=20

"Josh Howe" wrote on 10/27/2004 03:15:11 PM:

> Sorry, I don't think I was very clear. I'm asking a more generic
> question about control flow expressions. I want to run a sql statement
> but only if a certain condition is met, namely if a particular record
> exists in a table. I want to do it all in a single mysql statement,
like
> so:
>=20
> If ([record exists]) then
> Do some sql
> End If
>=20
> How can I do this? Thanks.=20
>=20
>=20
> -----Original Message-----
> From: Leo [mailto:leonardus@gmail.com]=20
> Sent: Tuesday, October 19, 2004 11:38 PM
> To: Josh Howe
> Cc: mysql@lists.mysql.com
> Subject: Re: what is wrong woth this statement?
>=20
> i didnt fully catch you...
> is this the kind of query statement you want?
>=20
> INSERT INTO some_other_table
> SELECT
> some_field_list
> FROM z_mail_systems
> HAVING COUNT(any_field)>0
>=20
>=20
> On Tue, 19 Oct 2004 12:45:30 -0400, Josh Howe wrote:
> > if (select count(*) from z_mail_systems > 0) then [insert statement]
> > endif;
> >=20
> > How do I do this kind of conditional insert? Thanks.
> >=20
> >
>=20
> --=20
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
> http://lists.mysql.com/mysql?unsub=3DWojciech.Matulewicz@nes tle.pl
>=20
>=20
>=20
>=20
> --=20
> MySQL General Mailing List
> For list archives: http://lists.mysql.com/mysql
> To unsubscribe:
http://lists.mysql.com/mysql?unsub=3Dsgreen@unimin.com
>=20


------_=_NextPart_001_01C4BC5E.AC28FBB2--

RE: what is wrong woth this statement?

am 27.10.2004 22:21:09 von SGreen

--=_alternative 006FFD7485256F3A_=
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: quoted-printable

You are right about your PRIMARY KEY and UNIQUE keys being able to protect =

most of your data. MySQL has an optional switch for INSERT, UPDATE, and=20
ALTER TABLE statements just for some of the situations you described. It's =

"IGNORE" and I can vouch that it works well.

http://dev.mysql.com/doc/mysql/en/INSERT.html
http://dev.mysql.com/doc/mysql/en/UPDATE.html
http://dev.mysql.com/doc/mysql/en/ALTER=5FTABLE.html

How can we detect that you have already altered a table to add a column to =

it? Not sure, the CREATE TABLE has an "IF NOT EXISTS" option but I don't=20
see one for ALTER TABLE ADD column=5Fname column=5Fdef

It may be safer, in your automated scripts, to create a new table with=20
the correct structure then copy the data over from the old table. Drop the =

old table, then rename the new one. Basically without the ability for your =

shell script to get any information from MySQL you are severely limiting=20
your options as to how much optional execution you can perform.

Shawn Green
Database Administrator
Unimin Corporation - Spruce Pine

"Josh Howe" wrote on 10/27/2004 03:52:45 PM:

>=20
> Thanks Shawn. Basically, our deployment mechanism involves applying=20
> sql change scripts as part of the build process. I created this=20
> simple shell script:
>=20
> host=3D"$1"
> user=3D"$2"
> pwd=3D"$3"
>=20
> mysql -u$user -p$pwd -h$host -f sinu=5Fcom <<=5FEOF=5F
>=20
> #Put the scripts to execute here:
> \. z=5Fworklog=5Falter.sql
> \. z=5Fcompanies=5Falter.sql
>=20
> quit
> =5FEOF=5F
>=20
>=20
> I?d like to be able to run this script multiple times against the=20
> same db without corrupting the data or structure, and without=20
> generating error messages that don?t indicate a real problem with=20
> one of the scripts (e.g. ?that column already exists?). To this end,
> I want to put code in all of the ?.sql? files so that it only=20
> executes once. E.g. if the sql is:
>=20
> Insert into users values (?myemail?,?mypassword?)
>=20
> I would want some thing like this:
>=20
> If(not exists(select * from users where username=3D?myemail?), Insert=20
> into users values (?myemail?,?mypassword?))
>=20
>=20
> I think I can protect against bad data with the proper keys and=20
> unique indexes. I?m not sure about this though. But even if I can=20
> protect the db from corruption, I will still get a bunch of primary=20
> key violations and such, and this will make it harder to extract the
> actual errors (e.g. syntax errors in the sql) when I run the script.
>=20
> So that?s why I want to do this. I hope that made sense. I guess=20
> that rather than trying to execute each script directly I can=20
> execute each via an intermediate perl script that updates the db to=20
> indicate which change scripts have been applied. That?s more complex
> though. Any ideas would be greatly appreciated. Thanks!=20
>=20
>=20
>=20
>=20
>=20
>=20
> From: SGreen@unimin.com [mailto:SGreen@unimin.com]=20
> Sent: Wednesday, October 27, 2004 3:30 PM
> To: Josh Howe
> Cc: Leo; mysql@lists.mysql.com
> Subject: RE: what is wrong woth this statement?
>=20
>=20
> Nearly all of the T-SQL style procedural statements (IF... BEGIN...=20
> END, WHILE...WEND, cursors, etc.) are not currently available in=20
> MySQL. Procedural scripts , like the one you propose, will be=20
> available in Stored Procedures (new to MySQL 5.0+). I haven't=20
> tested that version yet, so I can't tell you if it will support a=20
> statement like yours outside of a stored procedure (as a stand-alone
> statement).=20
>=20
> As of right now, you still need to make control-of-flow decisions in
> your programming language not your SQL statements. Sorry.=20
>=20
> Depending on what you are trying to do, there may be valid MySQL SQL
> statement or sequence of statements that will duplicate the behavior
> of the decision you are trying to make. Can you be very specific=20
> about what action(s) you want your statement to make?=20
>=20
> Shawn Green
> Database Administrator
> Unimin Corporation - Spruce Pine=20
>=20
> "Josh Howe" wrote on 10/27/2004 03:15:11 PM:
>=20
> > Sorry, I don't think I was very clear. I'm asking a more generic
> > question about control flow expressions. I want to run a sql statement
> > but only if a certain condition is met, namely if a particular record
> > exists in a table. I want to do it all in a single mysql statement,=20
like
> > so:
> >=20
> > If ([record exists]) then
> > Do some sql
> > End If
> >=20
> > How can I do this? Thanks.=20
> >=20
> >=20
> > -----Original Message-----
> > From: Leo [mailto:leonardus@gmail.com]=20
> > Sent: Tuesday, October 19, 2004 11:38 PM
> > To: Josh Howe
> > Cc: mysql@lists.mysql.com
> > Subject: Re: what is wrong woth this statement?
> >=20
> > i didnt fully catch you...
> > is this the kind of query statement you want?
> >=20
> > INSERT INTO some=5Fother=5Ftable
> > SELECT
> > some=5Ffield=5Flist
> > FROM z=5Fmail=5Fsystems
> > HAVING COUNT(any=5Ffield)>0
> >=20
> >=20
> > On Tue, 19 Oct 2004 12:45:30 -0400, Josh Howe wrote:
> > > if (select count(*) from z=5Fmail=5Fsystems > 0) then [insert stateme=
nt]
> > > endif;
> > >=20
> > > How do I do this kind of conditional insert? Thanks.
> > >=20
> > >
> >=20
> > --=20
> > MySQL General Mailing List
> > For list archives: http://lists.mysql.com/mysql
> > To unsubscribe:
> > http://lists.mysql.com/mysql?unsub=3DWojciech.Matulewicz@nes tle.pl
> >=20
> >=20
> >=20
> >=20
> > --=20
> > MySQL General Mailing List
> > For list archives: http://lists.mysql.com/mysql
> > To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dsgreen@unimin.com
> >=20
--=_alternative 006FFD7485256F3A_=--

Re: what is wrong woth this statement?

am 27.10.2004 22:50:48 von Rhino

Have you considered doing what you want to do in Ant? I haven't done exactly
what you want to do but Ant supports properties and conditions. I could
imagine an Ant task that determines if the desired record exists, then
another task that does an insert is executed only if the record doesn't
exist.

That might be easier than using a programming language if you have a major
reluctance to do programming.

Rhino
----- Original Message -----
From:
To: "Josh Howe"
Cc: "Leo" ;
Sent: Wednesday, October 27, 2004 3:29 PM
Subject: RE: what is wrong woth this statement?


> Nearly all of the T-SQL style procedural statements (IF... BEGIN... END,
> WHILE...WEND, cursors, etc.) are not currently available in MySQL.
> Procedural scripts , like the one you propose, will be available in Stored
> Procedures (new to MySQL 5.0+). I haven't tested that version yet, so I
> can't tell you if it will support a statement like yours outside of a
> stored procedure (as a stand-alone statement).
>
> As of right now, you still need to make control-of-flow decisions in your
> programming language not your SQL statements. Sorry.
>
> Depending on what you are trying to do, there may be valid MySQL SQL
> statement or sequence of statements that will duplicate the behavior of
> the decision you are trying to make. Can you be very specific about what
> action(s) you want your statement to make?
>
> Shawn Green
> Database Administrator
> Unimin Corporation - Spruce Pine
>
> "Josh Howe" wrote on 10/27/2004 03:15:11 PM:
>
> > Sorry, I don't think I was very clear. I'm asking a more generic
> > question about control flow expressions. I want to run a sql statement
> > but only if a certain condition is met, namely if a particular record
> > exists in a table. I want to do it all in a single mysql statement, like
> > so:
> >
> > If ([record exists]) then
> > Do some sql
> > End If
> >
> > How can I do this? Thanks.
> >
> >
> > -----Original Message-----
> > From: Leo [mailto:leonardus@gmail.com]
> > Sent: Tuesday, October 19, 2004 11:38 PM
> > To: Josh Howe
> > Cc: mysql@lists.mysql.com
> > Subject: Re: what is wrong woth this statement?
> >
> > i didnt fully catch you...
> > is this the kind of query statement you want?
> >
> > INSERT INTO some_other_table
> > SELECT
> > some_field_list
> > FROM z_mail_systems
> > HAVING COUNT(any_field)>0
> >
> >
> > On Tue, 19 Oct 2004 12:45:30 -0400, Josh Howe wrote:
> > > if (select count(*) from z_mail_systems > 0) then [insert statement]
> > > endif;
> > >
> > > How do I do this kind of conditional insert? Thanks.
> > >
> > >
> >
> > --
> > MySQL General Mailing List
> > For list archives: http://lists.mysql.com/mysql
> > To unsubscribe:
> > http://lists.mysql.com/mysql?unsub=Wojciech.Matulewicz@nestl e.pl
> >
> >
> >
> >
> > --
> > MySQL General Mailing List
> > For list archives: http://lists.mysql.com/mysql
> > To unsubscribe: http://lists.mysql.com/mysql?unsub=sgreen@unimin.com
> >
>


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=gcdmg-mysql@m.gmane.org

RE: what is wrong woth this statement?

am 27.10.2004 22:53:32 von Josh Howe

Thanks for all of the advice everybody. I'm actually a lot more
comfortable with perl than ANT so I think I'll use that. ANT does seem
pretty cool though, I'll need to buckle down and learn it at some point.


-----Original Message-----
From: Rhino [mailto:rhino1@sympatico.ca]=20
Sent: Wednesday, October 27, 2004 4:51 PM
To: Josh Howe; SGreen@unimin.com
Cc: Leo; mysql@lists.mysql.com
Subject: Re: what is wrong woth this statement?

Have you considered doing what you want to do in Ant? I haven't done
exactly
what you want to do but Ant supports properties and conditions. I could
imagine an Ant task that determines if the desired record exists, then
another task that does an insert is executed only if the record doesn't
exist.

That might be easier than using a programming language if you have a
major
reluctance to do programming.

Rhino
----- Original Message -----=20
From:
To: "Josh Howe"
Cc: "Leo" ;
Sent: Wednesday, October 27, 2004 3:29 PM
Subject: RE: what is wrong woth this statement?


> Nearly all of the T-SQL style procedural statements (IF... BEGIN...
END,
> WHILE...WEND, cursors, etc.) are not currently available in MySQL.
> Procedural scripts , like the one you propose, will be available in
Stored
> Procedures (new to MySQL 5.0+). I haven't tested that version yet, so
I
> can't tell you if it will support a statement like yours outside of a
> stored procedure (as a stand-alone statement).
>
> As of right now, you still need to make control-of-flow decisions in
your
> programming language not your SQL statements. Sorry.
>
> Depending on what you are trying to do, there may be valid MySQL SQL
> statement or sequence of statements that will duplicate the behavior
of
> the decision you are trying to make. Can you be very specific about
what
> action(s) you want your statement to make?
>
> Shawn Green
> Database Administrator
> Unimin Corporation - Spruce Pine
>
> "Josh Howe" wrote on 10/27/2004 03:15:11 PM:
>
> > Sorry, I don't think I was very clear. I'm asking a more generic
> > question about control flow expressions. I want to run a sql
statement
> > but only if a certain condition is met, namely if a particular
record
> > exists in a table. I want to do it all in a single mysql statement,
like
> > so:
> >
> > If ([record exists]) then
> > Do some sql
> > End If
> >
> > How can I do this? Thanks.
> >
> >
> > -----Original Message-----
> > From: Leo [mailto:leonardus@gmail.com]
> > Sent: Tuesday, October 19, 2004 11:38 PM
> > To: Josh Howe
> > Cc: mysql@lists.mysql.com
> > Subject: Re: what is wrong woth this statement?
> >
> > i didnt fully catch you...
> > is this the kind of query statement you want?
> >
> > INSERT INTO some_other_table
> > SELECT
> > some_field_list
> > FROM z_mail_systems
> > HAVING COUNT(any_field)>0
> >
> >
> > On Tue, 19 Oct 2004 12:45:30 -0400, Josh Howe
wrote:
> > > if (select count(*) from z_mail_systems > 0) then [insert
statement]
> > > endif;
> > >
> > > How do I do this kind of conditional insert? Thanks.
> > >
> > >
> >
> > --=20
> > MySQL General Mailing List
> > For list archives: http://lists.mysql.com/mysql
> > To unsubscribe:
> > http://lists.mysql.com/mysql?unsub=3DWojciech.Matulewicz@nes tle.pl
> >
> >
> >
> >
> > --=20
> > MySQL General Mailing List
> > For list archives: http://lists.mysql.com/mysql
> > To unsubscribe:
http://lists.mysql.com/mysql?unsub=3Dsgreen@unimin.com
> >
>




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/mysql?unsub=3Dgcdmg-mysql@m.gmane.org