How to execute mathematical expression stored in a varchar variable

前端 未结 4 1888
清歌不尽
清歌不尽 2021-01-13 13:03

I have a variable in my database function:

@LocalVariable = \'2*3*100\'

I want to get the result by executing the expression in another var

4条回答
  •  感情败类
    2021-01-13 13:40

    I got a better solution, I though of sharing with you all

    DECLARE @x xml
    DECLARE @v FLOAT
    SET @x = ''
    SET @v = @x.value('(1 + 4) div 3', 'FLOAT')
    SELECT @v
    

    This will work in function too.

提交回复
热议问题