日期:2014-05-17 浏览次数:20493 次
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-04-15 22:05:52
-- Version:
-- Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (Intel X86)
-- Jun 17 2011 00:57:23
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition on Windows NT 6.1 <X86> (Build 7601: Service Pack 1)
--
----------------------------
--> 测试数据:[TBL01]
if object_id('[TBL01]') is not null drop table [TBL01]
go
create table [TBL01]([ID] int,[PayInfo] varchar(26))
insert [TBL01]
select 1,'学费:100
------解决方案--------------------
杂费:20' union all
select 2,'学费:100
------解决方案--------------------
书本费:10' union all
select 3,'学费:100
------解决方案--------------------
杂费:20
------解决方案--------------------
保险费:10'
--> 测试数据:[PayItems]
if object_id('[PayItems]') is not null drop table [PayItems]
go
create table [PayItems]([ID] int,[MoneyName] varchar(6))
insert [PayItems]
select 1,'学费' union all
select 2,'杂费' union all
select 3,'书本费' union all
select 4,'保险费'
--------------开始查询--------------------------
SELECT id,[学费]=SUM(CASE WHEN payInfo='学费' THEN CONVERT(INT,[money]) ELSE 0 END ),