Home » SQL & PL/SQL » SQL & PL/SQL » Insert Multiple values on an If statement
Insert Multiple values on an If statement [message #36054] Thu, 01 November 2001 09:24 Go to next message
John Schaible
Messages: 1
Registered: November 2001
Junior Member
Hi,

I have an If statement I would like to shorten.
Basically, what I am trying to do is for every
value that meets the "IF" statement I want to
insert three different records into a table.

Currently I have three seperate "IF" statements to do
this. But I am sure there is a better way to acomplish this. Because, I have many more statements I need to write than just these three.

Example:

DESCRIBE TABLE A:
PartNumber Char(10),
Type Char(1),
Qty Number(5)

DESCRIBE TABLE B:
PartNumber Char(10),
Location Char(4),
Qty Number(5)

If A.type in ('N','P') Then
insert into B values(A.PartNumber,'FOOW',A.Qty);

If A.type in ('N','P') Then
insert into B values(A.PartNumber,'PADE',A.Qty);

If A.type in ('N','P') Then
insert into B values(A.PartNumber,'JCLW',A.Qty);

Now you can see the "IF" statement does not change,
but the value put into the "location" field in Table B does.

Any suggestions?

----------------------------------------------------------------------
Re: Insert Multiple values on an If statement [message #36055 is a reply to message #36054] Thu, 01 November 2001 10:04 Go to previous message
pb
Messages: 18
Registered: December 2000
Junior Member
Try the following:

If A.type in ('N','P') Then
insert into B values(A.PartNumber,'FOOW',A.Qty);
insert into B values(A.PartNumber,'PADE',A.Qty);
insert into B values(A.PartNumber,'JCLW',A.Qty);
End if;

----------------------------------------------------------------------
Previous Topic: Running SQL script/file
Next Topic: single quote
Goto Forum:
  


Current Time: Fri Nov 22 22:42:17 CST 2024