tratando valor para mudar virgula por ponto em procedure
Estou fazendo uma procedure que insere o valor de outra tabela em um campo, só que ocorre erro devido ao formato do valor vir como virgula para separar os decimais. Alguem sabe um modo de eu corrigir esse problema pelo proprio banco de dados?
Crie uma UDF para fazer essa correção :
e que é declarada assim no firebird:
mas quando eu faço um select simples:
ocorre o seguinte erro : ´connection lost to database´
usando IBOConsole ainda aparece essa msg e fecha o programa...
mas usando IBExpert nem aparece a msg ele já fecha a programa de vez...
alguem pode ajudar?
sds,
Crie uma UDF para fazer essa correção :
library ProgControl;
uses
SysUtils,
Classes;
{$R *.RES}
function TrocaVirPonto(valor: currency): string; stdcall; export;
var
I : Integer;
S, AString : string;
begin
AString := floattostr(valor);
S := ´´;
for I := 1 to Length(AString) do
if AString[I] = ´,´ then
S := S + ´.´
else
S := S + AString[I];
Result := S;
end;
exports
TrocaVirPonto index 1;
begin
end.
uses
SysUtils,
Classes;
{$R *.RES}
function TrocaVirPonto(valor: currency): string; stdcall; export;
var
I : Integer;
S, AString : string;
begin
AString := floattostr(valor);
S := ´´;
for I := 1 to Length(AString) do
if AString[I] = ´,´ then
S := S + ´.´
else
S := S + AString[I];
Result := S;
end;
exports
TrocaVirPonto index 1;
begin
end.
e que é declarada assim no firebird:
DECLARE EXTERNAL FUNCTION TROCAVIRPONTO NUMERIC(15, 2) RETURNS CSTRING(20) FREE_IT ENTRY_POINT ´TROCAVIRPONTO´ MODULE_NAME ´Progcontrol.dll´
mas quando eu faço um select simples:
Select referencia, descricao, TROCAVIRPONTO(PRECO_CUSTO) from Cad_Produtos where referencia = ´SA789´
ocorre o seguinte erro : ´connection lost to database´
usando IBOConsole ainda aparece essa msg e fecha o programa...
mas usando IBExpert nem aparece a msg ele já fecha a programa de vez...
alguem pode ajudar?
sds,
Marbravo
Curtidas 0
Respostas
Joaoshi
17/03/2008
Se os campos forem do mesmo tipo não deveria dar problema.
Se forem de tipos diferentes você poderia utilizar o [b:b3816f58c3]CAST[/b:b3816f58c3]
Espero ter ajudado.
Se forem de tipos diferentes você poderia utilizar o [b:b3816f58c3]CAST[/b:b3816f58c3]
Espero ter ajudado.
GOSTEI 0
Marbravo
17/03/2008
Segue a procedure para entender melhor
o problema está sendo o insert, o valor precisa ser com ponto e não virgula se não grava errado.
sds e aguardo ajuda.
CREATE PROCEDURE SP_AJUSTEESTTRANSF ( INPLOJA INTEGER, INPLOJAENTR INTEGER, INPREFERENCIA VARCHAR(10), INPCOR INTEGER, INPTAM VARCHAR(3), INPQUANT INTEGER) AS DECLARE VARIABLE VREFERENCIA VARCHAR(10); DECLARE VARIABLE VCOR INTEGER; DECLARE VARIABLE VLOJA INTEGER; DECLARE VARIABLE VTAMANHO INTEGER; DECLARE VARIABLE VT1 VARCHAR(3); DECLARE VARIABLE VT2 VARCHAR(3); DECLARE VARIABLE VT3 VARCHAR(3); DECLARE VARIABLE VT4 VARCHAR(3); DECLARE VARIABLE VT5 VARCHAR(3); DECLARE VARIABLE VT6 VARCHAR(3); DECLARE VARIABLE VT7 VARCHAR(3); DECLARE VARIABLE VT8 VARCHAR(3); DECLARE VARIABLE VT9 VARCHAR(3); DECLARE VARIABLE VT10 VARCHAR(3); DECLARE VARIABLE VDESCRICAO VARCHAR(45); DECLARE VARIABLE VNOMELOJA VARCHAR(35); DECLARE VARIABLE VPRECO_CUSTO NUMERIC(15,2); DECLARE VARIABLE VPRECO_UNIT NUMERIC(15,2); DECLARE VARIABLE VCONTADOR INTEGER; begin for select E.Referencia, E.Cor, E.Loja from Estoque E where E.referencia = :inpReferencia and E.Cor = :INPCor and E.loja = :inploja into :VReferencia, :VCor, :VLoja DO if (:Vreferencia = :inpreferencia) then Begin Execute procedure sp_abateestoque(:INPLOJA, :INPREFERENCIA, :INPCOR, :INPTAM, :INPQUANT); end for select E.Referencia, E.Cor, E.Loja from Estoque E where E.referencia = :inpReferencia and E.Cor = :INPCor and E.loja = :inplojaEntr into :VReferencia, :VCor, :VLoja DO if ((:Vreferencia <> ´´) and (:Vreferencia = :inpreferencia)) then Begin Execute procedure sp_acreestoque(:inplojaentr, :INPREFERENCIA, :INPCOR, :INPTAM, :INPQUANT); suspend; end else begin for select L.loja from Cad_Loja L where L.Loja = :inpLojaEntr into :VNomeLoja DO for select P.Tamanhos, P.descricao, P.preco_custo, P.Preco_venda from Cad_Produtos P where P.referencia = :inpReferencia into :VTamanho, :Vdescricao, :VPreco_Custo, :Vpreco_Unit DO for select T.T1, T.T2, T.T3, T.T4, T.T5, T.T6, T.T7, T.T8, T.T9, T.T10 from cad_tamanho T where T.Grupo = :Vtamanho into :VT1, :VT2, :VT3, :VT4, :VT5, :VT6, :VT7, :VT8, :VT9, :VT10 DO for Select Gen_id(GEN_Estoque, 1) from rdb$database into :VCONTADOR do execute statement ´Insert into estoque (Contador, Referencia, Descricao, data, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, Cor, Loja, Nome_loja, Preco_Unit, Preco_Custo) Values (´||:VCONTADOR||´, ´||´´´´||:INPREFERENCIA||´´´´||´, ´||´´´´||:VDESCRICAO||´´´´|| ´, current_date, ´||´´´´||:VT1||´´´´||´, ´||´´´´||:VT2||´´´´||´, ´||´´´´||:VT3||´´´´||´, ´||´´´´||:VT4||´´´´||´, ´||´´´´||:VT5||´´´´||´, ´||´´´´||:VT6||´´´´||´, ´||´´´´||:VT7||´´´´||´, ´||´´´´||:VT8||´´´´|| ´, ´||´´´´||:VT9||´´´´||´, ´||´´´´||:VT10||´´´´||´, ´||:INPCOR||´, ´||:inplojaentr||´, ´||´´´´||:Vnomeloja||´´´´||´, ´||:VPRECO_UNIT||´, ´||:VPreco_Custo||´)´; Execute procedure sp_acreestoque(:inplojaentr, :INPREFERENCIA, :INPCOR, :INPTAM, :INPQUANT); suspend; end end
o problema está sendo o insert, o valor precisa ser com ponto e não virgula se não grava errado.
sds e aguardo ajuda.
GOSTEI 0
Marbravo
17/03/2008
para ficar mais claro aki:
for select P.Tamanhos, P.descricao, [b:eeb6f8dc01]P.preco_custo, P.Preco_venda [/b:eeb6f8dc01]from Cad_Produtos P where P.referencia = :inpReferencia into :VTamanho, :Vdescricao, [b:eeb6f8dc01]:VPreco_Custo, :Vpreco_Unit[/b:eeb6f8dc01] DO
execute statement ´Insert into estoque (Contador, Referencia, Descricao, data, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, Cor, Loja, Nome_loja, Preco_Unit, Preco_Custo) Values (´||:VCONTADOR||´, ´||´´´´||:INPREFERENCIA||´´´´||´, ´||´´´´||:VDESCRICAO||´´´´||
´, current_date, ´||´´´´||:VT1||´´´´||´, ´||´´´´||:VT2||´´´´||´, ´||´´´´||:VT3||´´´´||´, ´||´´´´||:VT4||´´´´||´, ´||´´´´||:VT5||´´´´||´, ´||´´´´||:VT6||´´´´||´, ´||´´´´||:VT7||´´´´||´, ´||´´´´||:VT8||´´´´||
´, ´||´´´´||:VT9||´´´´||´, ´||´´´´||:VT10||´´´´||´, ´||:INPCOR||´, ´||:inplojaentr||´, ´||´´´´||:Vnomeloja||´´´´||´, [b:eeb6f8dc01]´||:VPRECO_UNIT||´, ´||:VPreco_Custo||[/b:eeb6f8dc01]´)´; :lol:
for select P.Tamanhos, P.descricao, [b:eeb6f8dc01]P.preco_custo, P.Preco_venda [/b:eeb6f8dc01]from Cad_Produtos P where P.referencia = :inpReferencia into :VTamanho, :Vdescricao, [b:eeb6f8dc01]:VPreco_Custo, :Vpreco_Unit[/b:eeb6f8dc01] DO
execute statement ´Insert into estoque (Contador, Referencia, Descricao, data, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, Cor, Loja, Nome_loja, Preco_Unit, Preco_Custo) Values (´||:VCONTADOR||´, ´||´´´´||:INPREFERENCIA||´´´´||´, ´||´´´´||:VDESCRICAO||´´´´||
´, current_date, ´||´´´´||:VT1||´´´´||´, ´||´´´´||:VT2||´´´´||´, ´||´´´´||:VT3||´´´´||´, ´||´´´´||:VT4||´´´´||´, ´||´´´´||:VT5||´´´´||´, ´||´´´´||:VT6||´´´´||´, ´||´´´´||:VT7||´´´´||´, ´||´´´´||:VT8||´´´´||
´, ´||´´´´||:VT9||´´´´||´, ´||´´´´||:VT10||´´´´||´, ´||:INPCOR||´, ´||:inplojaentr||´, ´||´´´´||:Vnomeloja||´´´´||´, [b:eeb6f8dc01]´||:VPRECO_UNIT||´, ´||:VPreco_Custo||[/b:eeb6f8dc01]´)´; :lol:
GOSTEI 0