读书人

如何用[^]相加

发布时间: 2012-09-03 09:48:39 作者: rapoo

怎么用[^]相加

例:

SQL code
id                        value----------------------------------------------------1                         22                         43                         8

得到要 2^4^8的值14


[解决办法]
sum([value])
[解决办法]
SQL code
declare @str varchar(20)set @str='';with tas(select 1 as id,2 as valueunion allselect 2 ,4union allselect 3,8)select @str=@str+'^'+ltrim(value) from tselect right(@str,len(@str)-1) as valuevalue2^4^8
[解决办法]
SQL code
declare @str int;with tas(select 1 as id,2 as valueunion allselect 2 ,4union allselect 3,8)select @str=isnull(@str,0)^value from tselect @str/*-----------14(1 行受影响)*/ 

读书人网 >SQL Server

热点推荐