Dear all
I am trying to insert into a table (0 to whatever number of records). One of the fields is incremented by one for each record. (It looks at another table and just takes the number and adds one to it). because my insert does them all in one go all records have the same number on them.
I need to be able to do the equivalant to a record set in VB so that I can insert each one at a time and then increment the table with the number on it ready for the next insert.
INSERT INTO payment(site_id,
income_date,
total_amount,
bank_date,
slip_no,
status,
payment_type,
rec_date,
fms_date,
site_pay_no,
amended)
SELECT p.site_id,
b.bank_date,
b.i_amount,
b.bank_date,
b.reference_numb,
'R',
'P',
convert(varchar,getdate(),103),
null,
s.next_pay_no + 1,
'N'
FROM bank b ,
payin_book p,
site s
WHERE reference_numb >= range_from
AND reference_numb <= range_to
AND p.site_id = s.site_id
AND b.status = 'R'
UPDATE site
SET next_pay_no = next_pay_no + 1
FROM site s, payment p
WHERE p.site_id = s.site_id
AND status = 'R'
I am trying to insert into a table (0 to whatever number of records). One of the fields is incremented by one for each record. (It looks at another table and just takes the number and adds one to it). because my insert does them all in one go all records have the same number on them.
I need to be able to do the equivalant to a record set in VB so that I can insert each one at a time and then increment the table with the number on it ready for the next insert.
INSERT INTO payment(site_id,
income_date,
total_amount,
bank_date,
slip_no,
status,
payment_type,
rec_date,
fms_date,
site_pay_no,
amended)
SELECT p.site_id,
b.bank_date,
b.i_amount,
b.bank_date,
b.reference_numb,
'R',
'P',
convert(varchar,getdate(),103),
null,
s.next_pay_no + 1,
'N'
FROM bank b ,
payin_book p,
site s
WHERE reference_numb >= range_from
AND reference_numb <= range_to
AND p.site_id = s.site_id
AND b.status = 'R'
UPDATE site
SET next_pay_no = next_pay_no + 1
FROM site s, payment p
WHERE p.site_id = s.site_id
AND status = 'R'