I've got a table which has columns customer_id, A, B, seq.
Customers can have multiples of A and B, and when this happens the seq gets incremented:
To make this simple, I want to write an INSERT that will add a row with the next available sequence number.
This works fine in SPUFI, and does exactly what I want - if there is no row already there, the null gets coalesced to zero, and one is added giving a seq of 1. If the max() returns a value, it gets incremented and the insert proceeds with the next available seq.
But as soon as I try to run this through the COBOL precompiler using host variables, it barfs at the syntax of the nested subselect. I've tried all sorts of combinations including INSERT with a fullselect using host variables and a nested subselect for the seq but nothing works.
I'm getting to the point where I think it will be easier to just do a separate SELECT to get the value into a host variable, but that seems like a cop-out
There doesn't seem to be anything in the manual that says you can't do this - does anyone have any ideas please?
Steve
[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object:erlDesignPatterns)[/small]
Customers can have multiples of A and B, and when this happens the seq gets incremented:
Code:
customer_id A B seq
1 1 1 1
1 1 1 2
1 2 1 1
1 2 2 1
Code:
insert into table (customer_id, A, B, seq)
values(1, 1, 1,
(select coalesce(max(seq), 0) + 1
from table
where customer_id = 1
and A = 1
and B = 1)
)
But as soon as I try to run this through the COBOL precompiler using host variables, it barfs at the syntax of the nested subselect. I've tried all sorts of combinations including INSERT with a fullselect using host variables and a nested subselect for the seq but nothing works.
I'm getting to the point where I think it will be easier to just do a separate SELECT to get the value into a host variable, but that seems like a cop-out
There doesn't seem to be anything in the manual that says you can't do this - does anyone have any ideas please?
Steve
[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object:erlDesignPatterns)[/small]