I am using SQL Server 2000 and in SP or Function, my problem is as follows:
I have one expression in variable of varchar. I want result of that
expression into another variable which is of numeric. For that code look
likes:
--code is as follows--
--Declaration of variables
declare @.str1 varchar (100)
declare @.int1 numeric (18, 2)
--This is assignment is for sampling purpose
select @.str1 = '2 + 2 * 8 / 3'
--Below sentence is my problem, I do not know the way of getting result of
expression in this situation
select @.int1 = cast(@.str1 as numeric)
--I need this value of variable for further use
select @.int1
--code ends here--
I will be thankful if problem get solved. Please note there are lots of code
before building expression and after getting result of this. I stuck up at
this point, as not able to convert string expression to numeric and hence
result.
Thank you in advance.Hi
You could do something like:
--code is as follows--
--Declaration of variables
DECLARE @.str1 varchar (100)
DECLARE @.int1 numeric (18, 2)
CREATE TABLE #tmp ( int1 numeric (18, 2) )
--This is assignment is for sampling purpose
SET @.str1 = 'SELECT (2 + (2 * 8)) / 3'
INSERT INTO #tmp ( int1 )
EXEC ( @.str1 )
SELECT @.int1 = int1 FROM #tmp
SELECT @.int1
DROP TABLE #tmp
But it would probably not be a very scallable solution.
John
"Kaushik Gadani" wrote:
> I am using SQL Server 2000 and in SP or Function, my problem is as follows:
> I have one expression in variable of varchar. I want result of that
> expression into another variable which is of numeric. For that code look
> likes:
> --code is as follows--
> --Declaration of variables
> declare @.str1 varchar (100)
> declare @.int1 numeric (18, 2)
> --This is assignment is for sampling purpose
> select @.str1 = '2 + 2 * 8 / 3'
> --Below sentence is my problem, I do not know the way of getting result of
> expression in this situation
> select @.int1 = cast(@.str1 as numeric)
> --I need this value of variable for further use
> select @.int1
> --code ends here--
> I will be thankful if problem get solved. Please note there are lots of code
> before building expression and after getting result of this. I stuck up at
> this point, as not able to convert string expression to numeric and hence
> result.
> Thank you in advance.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment