日期:2014-05-17 浏览次数:20404 次
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-12-04 13:20:59
-- Version:
-- Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
-- Dec 28 2012 20:23:12
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
--
----------------------------------------------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([ID] int,[CZ] varchar(19))
insert [huang]
select 62,'8100
------解决方案--------------------
5000
------解决方案--------------------
2000
------解决方案--------------------
3000' union all
select 79,'10000
------解决方案--------------------
1
------解决方案--------------------
1' union all
select 97,'10000' union all
select 103,'11' union all
select 104,'1
------解决方案--------------------
999' union all
select 120,'100' union all
select 122,'67
------解决方案--------------------
68
------解决方案--------------------
58' union all
select 124,'20
------解决方案--------------------
25' union all
select 125,'33
------解决方案--------------------
1
------解决方案--------------------
1'
--------------开始查询--------------------------
SELECT id,SUM([key]) [CZ]
FROM (
select
id,
CONVERT(INT,SUBSTRING([CZ],number,CHARINDEX('
------解决方案--------------------
',[CZ]+'
----