|
|
Question : TSQL decimal
|
|
What's wrong with following sql
Declare @Decimals Integer Declare @Digits Decimal DECLARE @myval varchar(9)
Set @Decimals = 3 Set @Digits = (9 - @Decimals) SET @myval = 193.57
select convert(decimal(@Digits,@Decimals),@myval)
Following line works but why i cannot pass a variable? select convert(decimal(9,3),@myval)
|
Answer : TSQL decimal
|
|
If myVal is currently VARCHAR and has a decimal point in it, you can do this to get a truncated value:
SELECT LEFT(myValue, CHARINDEX('.', myValue) + [decimal]) FROM myTable
|
|
|
|
|