I'm doing an application, in which I need to increment a sequence and check if that value has already been used in another table, because if it has already been I should ignore it and generate a new value for sequence until you find a unique value.
This is my SQL:
select nextval('controlesequencia')as proximo, -1 as soma
union
select currval('controlesequencia') as proximo, sum(quantidade) as soma from (
select count(*) as quantidade from manobrista where
CAST(('0' || COALESCE(segundo_codigo,'0')) AS INTEGER) = currval('controlesequencia')
union
select count(*) as quantidade from lancamento where
CAST(('0' || COALESCE(num_registro,'0')) AS INTEGER) = currval('controlesequencia') and data_saida = '') as mensalista
When I run Delphi, the value returned in nextval
is a strange character map.
DM.ProximoControle.FieldByName(Proximo).AsInteger;
How do I get the value correctly?