3
I’m making an application, in which I need to increment a quence and check if that value has already been used in another table, because if it has already been I must ignore and generate a new value for the quence 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 running in Delphi the value returned in nextval
is a strange character of the character map.
DM.ProximoControle.FieldByName(Proximo).AsInteger;
How do I get the value correctly?
You said when you run in Delphi it returns a strange character, what is it? If you try directly in the database sql works normally?
– Giovani
Could you show a little more code? Where did you see the strange character? It was in debug?
– falsarella
Directly in the database sql works normally without problem.
– Priscila Almeida
Delphi cannot convert the returned value to integer, when I switch to another return, for example, string the return is not an integer is a character.
– Priscila Almeida
//Procedure that opens sql, and executes query just opens and closes sql DM.Getproximocontrol() While DM.ProximoControle.eof do Begin if(DM.ProximoControle.Fieldbyname(SOMA).Asinteger =0) then Begin unico := DM.ProximoControle.Fieldbyname(PROXIMO). Asinteger; break; end; DM.ProximoControle.next; end;
– Priscila Almeida
You tried to cast for bigint ? type: select cast(nextval('controlesequencia') as bigint) as next, -1 as soma ...
– Vinicius
How did this code VC post is working if your while question is eof when it should be not eof ? @Priscila Almeida
– Wellington Silva Ribeiro