易截截图软件、单文件、免安装、纯绿色、仅160KB

sql行列互转(转帖)

--行列互转
/******************************************************************************************************************************************************
以学生成绩为例子,比较形象易懂
整理人:中国风(Roy)
日期:2008.06.06
******************************************************************************************************************************************************/
--1、行互列
--> --> (Roy)生成測試數據

if not object_id('Class') is null
drop table Class
Go
Create table Class([Student] nvarchar(2),[Course] nvarchar(2),[Score] int)
Insert Class
select N'张三',N'语文',78 union all
select N'张三',N'数学',87 union all
select N'张三',N'英语',82 union all
select N'张三',N'物理',90 union all
select N'李四',N'语文',65 union all
select N'李四',N'数学',77 union all
select N'李四',N'英语',65 union all
select N'李四',N'物理',85
Go
--2000方法:
动态:
declare @s nvarchar(4000)
set @s=''
Select @s=@s+','+quotename([Course])+'=max(case when [Course]='+quotename([Course],'''')+' then [Score] else 0 end)'
from Class group by[Course]
exec('select [Student]'+@s+' from Class group by [Student]')
生成静态:
select
[Student],
[数学]=max(case when [Course]='数学' then [Score] else 0 end),
[物理]=max(case when [Course]='物理' then [Score] else 0 end),
[英语]=max(case when [Course]='英语' then [Score] else 0 end),
[语文]=max(case when [Course]='语文' then [Score] else 0 end)
from
Class
group by [Student]
GO
--2005方法:
动态:
declare @s nvarchar(4000)
Select @s=isnull(@s+',','')+quotename([Course]) from Class group by[Course]
exec('select * from Class pivot (max([Score]) for [Course] in('+@s+'))b')
生成静态:
select *
from
Class
pivot
(max([Score]) for [Course] in([数学],[物理],[英语],[语文]))b
生成格式:
/*
Student 数学 物理 英语 语文
------- ----------- ----------- ----------- -----------
李四 77 85


相关文档:

DB2 纯SQL存储过程与函数的一些限制

*给多个变量赋值
function只能使用
set (a,b,c)=(select a,b,c from #);
procedure只能使用
select a,b,c into a,b,c from #
*function无法嵌套调用带有inout或out参数的procedure,现象为:无法创建。
 今天的进展结论是:
function可以调用任何procedure,但必须声明为modifies sql data,同时必须返回table ......

SQL Server 2000的数据库容量

-->目录
-->SQL Server 构架
-->实施细则
-->最大容量说明
 
最大值(数量或大小)
对象 SQL Server 7.0 SQL Server 2000
批处理大小 65,536 * 网络数据包大小1 65,536 * 网络数据包大小1
每个短字符串列的字节数 8,000 8,000
每个 text、ntext、或 image 列的字节数 2 GB-2 2 GB-2
每个 GROU ......

SQL数据库说明书

配置源程序
附加数据库SQL Server 2005
(1)将TM\01\App_Data文件夹中的db_SIS.mdf和db_SIS_log.ldf文件拷贝到SQL Server 2005安装路径下的MSSQL.1\MSSQL\Data目录下。
(2)选择开始/程序/Microsoft SQL Server 2005/SQL Server Management Studio项,进入到“连接到服务器”页面,如图1.1所示。
图1.1&nbs ......

sql数据库备份

sql server数据库备份方案
2008-08-05 13:15
SQL Server 数据库备份方案
为了保证SQL Server 数据的安全,数据库管理员应定期备份数据库,在不同情况下应采用不同备份数据库备份策略,一方面维持数据的安全性,另一方面也可保持SQL Server 能顺畅运行。尽最大的努力减少由于数据的损坏对客户造成的损失。
概念
1) 备份 ......

linq to sql 中的in 操作实现


        string s = " 80,81,83,82";
        string[] s1 = s.Split(',');
        int[] p = new int[s1.Count()];
        for (int i = 0; i < s1.Count( ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号