Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread IF-ELSE and INSERT INTO
Thu, Dec 21 2006 3:47 PMPermanent Link

Max Terentiev
Hello,

How can i use IF-ELSE function for SELECT and INSERT INTO statements ?

I want ot create query like this:

IF (SELECT MAX(CardNo) FROM "Cards")>10 THEN
      INSERT INTO Table1 (ID,Name) VALUES (10,'Jhon')
ELSE
      INSERT INTO Table2 (ID2,Name2) VALUES(20,'Smith')

It's possible ?

Thanx for help !
Thu, Dec 21 2006 4:10 PMPermanent Link

Max Terentiev
Also, it's possible to use WHERE in IF-SELECT statement ?

IF (SELECT MAX(CardNo) FROM "Cards" WHERE CardType=25)>10 THEN
      INSERT INTO Table1 (ID,Name) VALUES (10,'Jhon')
ELSE
      INSERT INTO Table2 (ID2,Name2) VALUES(20,'Smith')
Thu, Dec 21 2006 4:50 PMPermanent Link

"Robert"

"Max Terentiev" <maxterentiev@mail.ru> wrote in message
news:077B2204-B13D-4459-AEDA-7D10702BD9D5@news.elevatesoft.com...
> Hello,
>
> How can i use IF-ELSE function for SELECT and INSERT INTO statements ?
>
> I want ot create query like this:
>
> IF (SELECT MAX(CardNo) FROM "Cards")>10 THEN
>       INSERT INTO Table1 (ID,Name) VALUES (10,'Jhon')
> ELSE
>       INSERT INTO Table2 (ID2,Name2) VALUES(20,'Smith')
>

SELECT MAX(CARDNO) MAXID INTO MEMORY\TEMP FROM CARDS;
INSERT INTO TABLE1 (ID, NAME) SELECT 10, 'JOHN' FROM MEMORY\TEMP WHERE MAXID
> 10;
INSERT INTO TABLE2 (ID, NAME) SELECT 20, 'SMITH' FROM MEMORY\TEMP WHERE
MAXID <= 10;

Robert

Image