我有张桌子。在这个表中有一些样本数据。
表数据:
从表中选择col1
结果集:
col1
1+2+3+45-6+7+8-9
1+2+3+45-6+7+89
1+2+3+45-6+7-8+9
1+2+3+45-6+7-8-9
..。
。。
。
有计算列数据的方法吗?
就像这样:
从表中选择col1,计算(Col1)为col2
商品、商品、金融、金融等领域。
1+2+3+45-6+7+8-9
1+2+3+45-6+7+89
1+2+3+45-6+7-8+9
1+2+3+45-6+7-8-9
发布于 2017-04-26 12:40:10
只是为了好玩
Declare @YourTable table (col1 varchar(100))
Insert Into @YourTable values
('1+2+3+45-6+7+8-9'),
('1+2+3+45-6+7+89'),
('1+2+3+45-6+7-8+9'),
('1+2+3+45-6+7-8-9')
Declare @SQL varchar(max) = ''
Select @SQL = @SQL + ',('''+col1+''','+col1+')' From @YourTable
Select @SQL = 'Select * From (values '+Stuff(@SQL,1,1,'')+') A (col1,col2)'
Exec(@SQL)返回
col1 col2
1+2+3+45-6+7+8-9 51
1+2+3+45-6+7+89 141
1+2+3+45-6+7-8+9 53
1+2+3+45-6+7-8-9 35https://stackoverflow.com/questions/43632931
复制相似问题