日期:2014-05-18  浏览次数:20544 次

怎么用[^]相加

例:
SQL code

id                        value
----------------------------------------------------
1                         2
2                         4
3                         8


得到要 2^4^8的值14


------解决方案--------------------
sum([value])
------解决方案--------------------
SQL code

declare @str varchar(20)
set @str=''
;with t
as(
select 1 as id,2 as value
union all
select 2 ,4
union all
select 3,8
)
select @str=@str+'^'+ltrim(value) from t
select right(@str,len(@str)-1) as value

value
2^4^8

------解决方案--------------------
SQL code
declare @str int

;with t
as(
select 1 as id,2 as value
union all
select 2 ,4
union all
select 3,8
)
select @str=isnull(@str,0)^value from t


select @str

/*-----------
14

(1 行受影响)
*/