Error converting varchar field to float

Asked

Viewed 617 times

0

I am generating a Query and in this Query I am making a Join between a field varchar and a field float.

Being the field SY.YE_MOEDA is varchar and the countryside DA1_A1_MOEDA is float.

Follow my Query:

SELECT
DA.DA1_CODTAB  AS TABELA,
DA.DA1_CODPRO  AS CODPRODUTO,
SB.B1_DESC     AS DESCRICAO,
SB.B1_PRV1     AS PRECOVENDA,
DA.DA1_MOEDA   AS MOEDA,
SY.YE_MOEDA    AS NOMEMOEDA
FROM DA1010 AS DA
INNER JOIN SB1010 AS SB WITH (NOLOCK) ON SB.B1_COD = DA.DA1_CODPRO
INNER JOIN SYE010 AS SY WITH (NOLOCK) ON CONVERT(FLOAT, ISNULL(SY.YE_MOEDA,0)) = DA.DA1_MOEDA
WHERE DA.D_E_L_E_T_ <> '*' AND DA.DA1_ATIVO = '1'

Follow the error

Msg 8114, Level 16, State 5, Line 1 Error Converting data type varchar to float.

  • This is the Protheus?

  • Yes protheus, but I was able to solve the problem, in the table where the value of the coin had a hidden field with the currency code of type float, and this field solved the Join problem. But thank you very much for your attention

  • Coin float is very wrong. https://answall.com/a/38140/101

1 answer

0

In the oracle there is a trick to make this conversion:

select meuCampo + 0.0 as comoFloat from minhaTabela

I suppose it works in sql serve.

Another solution is to change the Convert to decimal, getting:

SELECT
DA.DA1_CODTAB  AS TABELA,
DA.DA1_CODPRO  AS CODPRODUTO,
SB.B1_DESC     AS DESCRICAO,
SB.B1_PRV1     AS PRECOVENDA,
DA.DA1_MOEDA   AS MOEDA,
SY.YE_MOEDA    AS NOMEMOEDA
FROM DA1010 AS DA
INNER JOIN SB1010 AS SB WITH (NOLOCK) ON SB.B1_COD = DA.DA1_CODPRO
INNER JOIN SYE010 AS SY WITH (NOLOCK) ON CONVERT(DECIMAL, ISNULL(SY.YE_MOEDA,0)) = DA.DA1_MOEDA
WHERE DA.D_E_L_E_T_ <> '*' AND DA.DA1_ATIVO = '1'
  • Yes protheus, but I was able to solve the problem, in the table where the value of the coin had a hidden field with the currency code of type float, and this field solved the Join problem. But thank you very much for your attention.

  • GOOD SHOW :)

  • Custom table in Protheus with numerical "key", you regret being born .... :)

Browser other questions tagged

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