简体   繁体   English

在SQL Server中从varchar转换为numeric

[英]Conversion from varchar to numeric in SQL Server

In my table data is stored as ((1000.000) + 200.000) + 1000.00 在我的表中,数据存储为((1000.000) + 200.000) + 1000.00

Data type of the column is nvarchar . 列的数据类型是nvarchar

I would like get the output while selecting the table as 2200.000 我想在选择表格时获得输出为2200.000

Use dynamic sql 使用动态sql

declare @query varchar(max) = 'select ((1000.000) + 200.000) + 1000.00'

exec(@query)

this this... 这个......

CREATE TABLE table3
(
    formula_id int,
    formula varchar(max)
)

INSERT INTO table3 (formula_id, formula)
VALUES
(1, '((1000.000) + 200.000) + 1000.00')

DECLARE @formula varchar(max)
SELECT @formula = formula FROM table3 WHERE formula_id = 1    
DECLARE @query varchar(max) = 'SELECT ' + @formula
EXEC(@query)

Note : The last 4 query must run at the same time, else no result will be shown. 注意:最后4个查询必须同时运行,否则不会显示任何结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM