Hi All:
I have varchar values like '01234560' that I need to convert to decimals like 123.456. The length of the varchar values change, so I'd like to be able to do something like:
DECLARE @var1 varchar(8) , @var2 int
SET @var1 = SUBSTRING('0123456', 1, 4) + '.' + SUBSTRING('0123456', 5, 3)
SET @var2 = LEN(@var1)
SELECT convert(decimal(@var2, 4),@var1)
This fails: SELECT convert(decimal(@var2[/color red], 4),@var1)
However, this succeeds: SELECT convert(decimal(8[/color red], 4),@var1)
Any ideas why this won't work?
TIA,
Sven
I have varchar values like '01234560' that I need to convert to decimals like 123.456. The length of the varchar values change, so I'd like to be able to do something like:
DECLARE @var1 varchar(8) , @var2 int
SET @var1 = SUBSTRING('0123456', 1, 4) + '.' + SUBSTRING('0123456', 5, 3)
SET @var2 = LEN(@var1)
SELECT convert(decimal(@var2, 4),@var1)
This fails: SELECT convert(decimal(@var2[/color red], 4),@var1)
However, this succeeds: SELECT convert(decimal(8[/color red], 4),@var1)
Any ideas why this won't work?
TIA,
Sven