动态关联表
来源:互联网 发布:淘宝网店交流群 编辑:程序博客网 时间:2024/05/21 10:11
原帖地址:
http://community.csdn.net/Expert/topic/3452/3452577.xml?temp=.1377375
--示例数据
create table [table](A sysname,B varchar(10))
insert [table] select 'table_1','a'
union all select 'table_2','b'
create table table_1(A int)
insert table_1 select 1
union all select 2
create table table_2(A int)
insert table_2 select 3
union all select 4
go
/*--问题说明:
table中,A字段存储着其他表的名称
A字段中,记录和各个表的A字段的最大值
即得到如下结果:
table.B C
-------- -----------
a 1
b 2
--*/
--处理方法
declare @s varchar(8000)
set @s=''
select @s=@s+' when '''+A+''' then(select max(A) from ['+A+'])'
from [table] group by A
exec('select B,C=case A'+@s+' end from [table]')
go
--删除测试
drop table [table],table_1,table_2
/*--测试结果
B C
---------- -----------
a 2
b 4
--*/
Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=137010
- 动态关联表
- 动态关联表
- 动态关联表
- 动态关联表
- 动态关联表
- 动态关联表
- 动态关联表
- 动态关联表
- 动态关联表
- 动态关联表
- 动态关联表
- 动态关联表
- 动态关联表
- 动态关联表
- ClearQuest的动态关联
- EditText动态关联TextView
- iOS动态关联对象
- C++中的静态关联与动态关联
- SQL Server BUG集之"自定义函数与group by"
- 字段里字符串的处理问题
- 根据产品损耗率计算产品实际数量
- Jpage分页 .net2.0版 通用.net2.0分页程序
- 使用 Microsoft.NET Frameworks 创建Windows应用程序
- 动态关联表
- 随机排序分页处理示例
- Windows2000 DNS 技术指南 1
- 2007年技术图书出版,我们有多少“第一本”?
- 分拆统计字符串
- 交叉报表处理实例
- 用SQL语句来建立跟踪的问题
- 字符串分拆查询
- 无规律自定义分段的分类汇总+交叉表处理