Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread query advice
Sun, Aug 19 2007 7:31 PMPermanent Link

Jim Margarit
Is there a single query that will add a record to table B for every record in table A?

For example: Add a record consisting of  accountID and parameter :FuelSurcharge to an invoice table for every existing account.

Right now, I select all accounts and loop through them and add records to the invoice table. Seems like there should be an SQL way to do it.

Thanks,

Jim

Sun, Aug 19 2007 10:24 PMPermanent Link

"Robert"

"Jim Margarit" <mailATdrmargarit.com> wrote in message
news:3D844BA7-0129-4CE3-84F8-4FFB7C29F333@news.elevatesoft.com...
> Is there a single query that will add a record to table B for every record
> in table A?
>
> For example: Add a record consisting of  accountID and parameter
> :FuelSurcharge to an invoice table for every existing account.
>
> Right now, I select all accounts and loop through them and add records to
> the invoice table. Seems like there should be an SQL way to do it.
>

INSERT INTO "Customer" (CustNo, Company)
SELECT CustNo, Company
FROM "OldCustomer"


Mon, Aug 20 2007 11:14 AMPermanent Link

Jim Margarit
Robert wrote:
> "Jim Margarit" <mailATdrmargarit.com> wrote in message
> news:3D844BA7-0129-4CE3-84F8-4FFB7C29F333@news.elevatesoft.com...
>> Is there a single query that will add a record to table B for every record
>> in table A?
>>
>> For example: Add a record consisting of  accountID and parameter
>> :FuelSurcharge to an invoice table for every existing account.
>>
>> Right now, I select all accounts and loop through them and add records to
>> the invoice table. Seems like there should be an SQL way to do it.
>>
>
> INSERT INTO "Customer" (CustNo, Company)
> SELECT CustNo, Company
> FROM "OldCustomer"
>
>
>
After a lot of post searching, it turned out to be (off the top of my
head, not cut and paste):

INSERT INTO invoice (acctID,fee)
select acctID, cast(:fuelSurcharge as integer) from account

which is much much much faster than looping through and inserting. I
never would have pulled that out from any of the help files. Getting the
parameter to work was the hard part.

Jim Margarit
Image