Actions based on conditions

Actions based on conditions

am 01.04.2005 18:23:48 von How Loon

Greetings,

How to I contruct a SQL script to execute INSERT or
UPDATE command based on the condition?


EXAMPLE
=======
SET @IntPaidToMonth := 1;
SET @ActualWDBI := 2;
SET @MonthlyInterest := 3;

if @IntPaidToMonth + @ActualWDBI <= @MonthlyInterest
then
begin
INSERT SOMETHING...
end

else

begin
UPDATE SOMETHING...
end


Thanks.



__________________________________
Do you Yahoo!?
Yahoo! Small Business - Try our new resources site!
http://smallbusiness.yahoo.com/resources/

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

Re: Actions based on conditions

am 01.04.2005 18:32:07 von Corey Tisdale

Look at replace syntax

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

-Corey


ascll wrote:

>Greetings,
>
>How to I contruct a SQL script to execute INSERT or
>UPDATE command based on the condition?
>
>
>EXAMPLE
>=======
>SET @IntPaidToMonth := 1;
>SET @ActualWDBI := 2;
>SET @MonthlyInterest := 3;
>
> if @IntPaidToMonth + @ActualWDBI <= @MonthlyInterest
>then
> begin
> INSERT SOMETHING...
> end
>
> else
>
> begin
> UPDATE SOMETHING...
> end
>
>
>Thanks.
>
>
>
>__________________________________
>Do you Yahoo!?
>Yahoo! Small Business - Try our new resources site!
>http://smallbusiness.yahoo.com/resources/
>
>
>


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

Re: Actions based on conditions

am 01.04.2005 18:34:37 von Jan Theodore Galkowski

Which version of MySQL are you using here? v5 or v4?

With v5 you can use stored procedures.

With v4 one way is to create a special table having a singleton row
recording the values of @IntPaidToMonth, @ActualWDBI, @MonthlyInterest.
Then cite that table in FROM and WHERE clauses using @IntPaidToMonth +
@ActualWDBI <=3D @MonthlyInterest as a condition in the sequence

INSERT INTO something SELECT ... WHERE ...

UPDATE something WHERE ...

DELETE FROM something WHERE ...

The idea being to always insert the something, update the proper
something if one should, and delete the extra something if the update
case was proper.

-jtg

On Fri, 1 Apr 2005 08:23:48 -0800 (PST), "ascll" said:
> Greetings,
>
> How to I contruct a SQL script to execute INSERT or UPDATE command
> based on the condition?
>
>
> EXAMPLE
> =======3D
> SET @IntPaidToMonth :=3D 1; SET @ActualWDBI :=3D 2; SET
> @MonthlyInterest :=3D 3;
>
> if @IntPaidToMonth + @ActualWDBI <=3D @MonthlyInterest then begin
> INSERT SOMETHING... end
>
> else
>
> begin UPDATE SOMETHING... end
>


[snip]

--=20
Jan Theodore Galkowski (o°) =

jtgalkowski@alum.mit.edu
http://www.smalltalkidiom.net



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

Re: Actions based on conditions

am 01.04.2005 18:38:15 von Jan Theodore Galkowski

Excellent and better! Alas, AFAIK not standard SQL. If you're using
MySQL, that should not trouble you.

Also see the caution at the link Corey providing about InnoDB.

- jtg

On Fri, 01 Apr 2005 10:32:07 -0600, "Corey Tisdale"
said:
> Look at replace syntax
>
> http://dev.mysql.com/doc/mysql/en/replace.html
>
> -Corey
>
>
> ascll wrote:
>
> >Greetings,
> >
> >How to I contruct a SQL script to execute INSERT or UPDATE command
> >based on the condition?
> >
> >
> >EXAMPLE
> >=======
> >SET @IntPaidToMonth := 1; SET @ActualWDBI := 2; SET
> >@MonthlyInterest := 3;
> >
> > if @IntPaidToMonth + @ActualWDBI <= @MonthlyInterest then begin
> > INSERT SOMETHING... end
> >
> > else
> >
> > begin UPDATE SOMETHING... end
> >


[snip]


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