练习行列转换 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]
--动态方法
--三个单引号,其中有两个单引号是转义字符,两个单引号相当于一个单引号,还有一个单引号是连接字符串用的
相关文档:
随机读取若干条记录,测试过
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 ......
我在使用PL/SQL时,点击某个字段旁边的小按钮希望弹出编辑窗口时,PL/SQL提示“无效的窗口句柄”。一直不明白是怎么回事,后来baidu了下,才知道这个功能和windows的print spooler服务有关。启动该服务就可以了。 ......
日志读取器只将已经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& ......
SQL Native Client ODBC Driver
标准安全连接
Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
您是否在使用SQL Server 2005 Express 请在“Server”选项使用连接表达式“主机名称\SQLEXPRESS”。
受信的连接
Driver={SQL Native ......
IN
确定给定的值是否与子查询或列表中的值相匹配。
EXISTS
指定一个子查询,检测行的存在。
比较使用 EXISTS 和 IN 的查询
这个例子比较了两个语义类似的查询。第一个查询使用 EXISTS 而第二个查询使用 IN。注意两个查询返回相同的信息。
USE pubs
GO
SELECT DISTINCT pub_name
from publishers
WHERE ......