I have a temp Table in SQL Server that is created and populated from a flat text file that we receive on a monthly basis. All fields in this temp table are defined as varchar.From this temp table 3 other tables are populated from the date, however, several fields need to be converted to other data types along with some other string manipulation. I have the one manipulation taken care of but I can't get the data to convert to either a decimal or money. Neither CAST nor CONVERT works. Here's the function:alter function replaceSymbol (@result varchar(20))returns varchar(20) -- tried decimal and money, receive errorsasbegin--Declare @result varchar(500)Declare @cent varchar(5)Declare @dollar varchar(25)Declare @xLen intDeclare @type_amount intDeclare @strDel char(1)-- if last character symbol is below, amount needs to be negativeif right(@result, 1) = '}' or right(@result, 1) = 'J' or right(@result, 1) = 'K' or right(@result, 1) = 'L' or right(@result, 1) = 'M' or right(@result, 1) = 'N' or right(@result, 1) = 'O' or right(@result, 1) = 'P' or right(@result, 1) = 'Q' or right(@result, 1) = 'R'begin set @type_amount = 1endset @result = replace(@result,'{','0')set @result = replace(@result,'A','1')set @result = replace(@result,'B','2')set @result = replace(@result,'C','3')set @result = replace(@result,'D','4')set @result = replace(@result,'E','5')set @result = replace(@result,'F','6')set @result = replace(@result,'G','7')set @result = replace(@result,'H','8')set @result = replace(@result,'I','9')set @result = replace(@result,'}','0')set @result = replace(@result,'J','1')set @result = replace(@result,'K','2')set @result = replace(@result,'L','3')set @result = replace(@result,'M','4')set @result = replace(@result,'N','5')set @result = replace(@result,'O','6')set @result = replace(@result,'P','7')set @result = replace(@result,'Q','8')set @result = replace(@result,'R','9')set @xLen = len(@result)set @cent = right(@result, 2)set @dollar = left(@result, @xLen-2)set @strDel = '.'set @result = @dollar+@strDel+@cent-- tried doing convert and cast, get errors-- changing value to negative figureif @type_amount = 1begin set @result = @result*-1endreturn @resultendManipulation requires that I convert the last symbol in the string and add a decimal(.) before the last 2 numbers. This is then an amount that needs to be inserted into a datatype field of money in the new table.However, when I process the function with the following, I get the following error:Declare @test varchar(20)set @test = '1234567R'select dbo.replaceSymbol(@test) as testSyntax error converting the varchar value '123456.79' to a column of data type int.
What am I missing in this? Or what else do I need to do? This is my first using SQL Server stored procedures, custom functions, etc. If I run this function without the line in red (indicated above) I get the figure: (but I need to determine if it's positive or negative)123456.79
Any help you can provide would be greatly appreciated.Thank you.