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

练习行列转换 sql server 2000

依据csdn高手写的自己练习一下方便以后查找
--Creator:Gongl
--Date:2009-1-8
--sql server 2000
--学习行转列,为了进一步了解动态sql拼接(单双三引号)
--几种类型
--Numeric(10,2) 指字段是数字型,长度为10 小数为两位
--varchar和nvarchar的区别
--1.从存储方式上,nvarchar是按字符存储的,而 varchar是按字节存储的;
--2.从存储量上考虑, varchar比较节省空间,因为存储大小为字节的实际长度,而 nvarchar是双字节存储;
--3.在使用上,如果存储内容都是英文字符而没有汉字等其他语言符号,建议使用varchar;含有汉字的使用nvarchar,因为nvarchar是使用Unicode编码,即统一的字符编码标准,会减少乱码的出现几率;
----行转列
--创建测试数据
if object_id('idl') is not null drop table idl
create table idl(name varchar(10),subject nvarchar(10),score numeric(4,1))
insert into idl
select 'anny','数学',95.5 union all
select 'anny','语文',90 union all
select 'anny','英语',99 union all
select 'anny','asp.net',100 union all
select 'anny','sqlserver',100 union all
select 'jenny','数学',94.5 union all
select 'jenny','语文',59.5 union all
select 'jenny','asp.net',100
--静态方法1
select [name],
 max(case subject when '数学' then score else 0 end) [数学],
 max(case subject when '语文' then score else 0 end) [语文],
 max(case subject when '英语' then score else 0 end) [英语],
 max(case subject when 'asp.net' then score else 0 end) [asp.net],
 max(case subject when 'sqlserver' then score else 0 end) [sqlserver]
from idl
group by [name]
--静态方法2
select [name],
 max(isnull((case subject when '数学' then score end),0)) [数学],
 max(isnull((case subject when '语文' then score end),0)) [语文],
 max(isnull((case subject when '英语' then score end),0)) [英语],
 isnull(max(case subject when 'asp.net' then score end),0) [asp.net],
 isnull(max(case subject when 'sqlserver' then score end),0) [sqlserver]
from idl
group by [name]
--动态方法
--三个单引号,其中有两个单引号是转义字符,两个单引号相当于一个单引号,还有一个单引号是连接字符串用的


相关文档:

SQL Server和Oracle的常用函数比较

---------数学函数 ---------------
  1.绝对值
  S:select abs(-1) value
  O:select abs(-1) value from dual
  2.取整(大)
  S:select ceiling(-1.001) value
  O:select ceil(-1.001) value from dual
  3.取整(小)
  S:select floor(-1.001) value
  O:select floor(-1.001) value from ......

有用的sql语句

  随机读取若干条记录,测试过
Access语法:SELECT top 10 * from 表名 ORDER BY Rnd(id)
Sql server:select top n * from 表名 order by newid()
mysql select * from 表名 Order By rand() Limit n
  说明:选择从10到15的记录
select top 5 * from (select top 15 * from table order by id asc) table_别名 or ......

经典SQL语句大全

经典SQL语句大全
下列语句部分是Mssql语句,不可以在access中使用。
  SQL分类:
  DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE)
  DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT)
  DCL—数据控制语言(GRANT,REVOKE,COMMIT,ROLLBACK)
  首先,简要介绍基础语句:
  1、 ......

SQL SERVER 用sql语句如何获得当前系统时间


SQL SERVER 2000用sql语句如何获得当前系统时间
就是用GETDATE();
Sql中的getDate()2008年01月08日 星期二 14:59
Sql Server 中一个非常强大的日期格式化函数
Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2008 10:57AM
Select CONVERT(varchar(100), GETDATE(), 1): 05/16/08
Select CONVERT(varchar(100), ......

SQL SERVER事务复制--工作原理测试

日志读取器只将已经COMMIT的事务传送到分发数据库。
测试方法:
1. 在发布数据库执行:
begin tran
insert  testTable2 (aaa,bbb,ddd,ccc)
values ('jawefwao','jfowijef','jaiwejfo','civjoiw')
insert  testTable2 (aaa,bbb,ddd,ccc)
values ('jawefwao2','jfowijef2','jaiwejfo2','civjoiw2')
insert& ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号