How to remove the decimal separator from a result?

Asked

Viewed 524 times

-1

In the sql query I have a total order value multiplied by 1000:

Total value: 195.41 Value Viewed: 195410.00

How could I remove the separator?

SELECT CAST(CONVERT(varchar, CAST(195410.00 AS money), 0) AS varchar)

  • Multiplying by 100?

2 answers

0

You can make a convert for int, see how it looks

declare @valor_total decimal(18,2) = 195.41

select convert(int, @valor_total*1000)
  • Very good, that’s right

-1


As commented by @Maniero, just multiply the value by 100 instead of 1000.

If you do not have management over this multiplication, the conversion to INT suggested by @Pablovargas is also valid, provided that the value is not higher than that admitted by the field (-2.147.483.648) to 2 31-1 (2.147.483.647) - https://msdn.microsoft.com/pt-br/library/ms187745.aspx)

Conversion to INT:

SELECT CAST(195410.00 AS INT)

It is also possible to simply delete the characters after the point:

select LEFT(195410.00, CHARINDEX('.', 195410.00) - 1)
  • thanks worked out ! friend

  • Cool. Only gives an ok on the answer. Tks

Browser other questions tagged

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