Error converting varchar data type to float

Asked

Viewed 625 times

0

I have a stored precedent to change a field of tables of varied name:

CREATE PROCEDURE usp_alterarCrachaCadAce
--PARÂMETROS
@NomeTabela VARCHAR(20),
@CrachaDestino FLOAT,
@CrachaOrigem FLOAT


AS
BEGIN



Declare @Comando Varchar(1000)

Set @Comando = 'UPDATE '+@NomeTabela +' SET ace_ cracha = '+@CrachaDestino+ ' WHERE ace_cracha = '+@CrachaOrigem

Exec(@Comando)



END

however it is giving an error that I did not understand very well when running the sp:

Mensagem 8114, Nível 16, Estado 5, Procedimento usp_alterarCrachaCadAce, 

Linha 17
Erro ao converter tipo de dados varchar em float.

OBS: the data being passed is DOUBLE, but I did not find any way to declare double in SQL, so I understood I should use the same float.

1 answer

0


To concatenate a numeric type to a text you must convert it to text, otherwise the database will try to perform a sum:

SET @comando = 'UPDATE ' + @NomeTabela + ' SET ace_ cracha = ' + CAST(@CrachaDestino AS VARCHAR(100)) + ' WHERE ace_cracha = ' + CAST(@CrachaOrigem AS VARCHAR(100));
  • Perfect! When running the sp directly in Management Studio, it works. However, when I try to call sp in my Repository, it returns: Caused by: com.microsoft.sqlserver.jdbc.Sqlserverexception: The statement Did not Return a result set.

  • @cidadaox there is another error in the application. Open another question with the necessary information so that we can see what can be done to help you

  • I am working with Spring, had forgotten the Transactional and Modifying annotations to inform that it is a change query. Now it’s perfect, thank you very much friend

Browser other questions tagged

You are not signed in. Login or sign up in order to post.