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

在SQL Server 删除重复数据

删除数据库表中某一字段的重复纪录,只想保留一条记录可用以下方法:
执行以下语句:
declare @max integer,@id varchar(18) --此处变量类型根据字段类型设置
declare cur_rows cursor local for select 字段,count(*) from 表名group by 字段 having count(*) > 1
open cur_rows
fetch cur_rows into @id,@max
while @@fetch_status=0
begin
 select @max = @max -1
 set rowcount @max
 delete from 表名where 字段 = @id
 fetch cur_rows into @id,@max
end
close cur_rows
set rowcount 0


相关文档:

使用SQL*PLUS构建完美excel或html输出

转自:http://hong9270503.blog.163.com/blog/static/127292320091611319516/
通过SQL*PLUS我们可以构建友好的输出,满足多样化用户需求。
  
本例通过简单示例,介绍通过sql*plus输出xls,html两种格式文件.
   首先创建两个脚本:
  
1.main.sql
   用以设置环境,调用具体功能脚本
   2.功能脚本-ge ......

Access 的 SQL 的记录间的加减计算

Access 的 SQL 中,计算相应编号的记录之间 加 减 的查询命令
例如 计算ID为 6 的 合计 减去 ID 为 2、3、4 以及加上 ID 为 5 的合计
SELECT SUM(R) AS 结果
from
(
  SELECT 合计  AS R from T1 WHERE (ID = 6) UNION
  SELECT -合计 AS R from T1 WHERE (ID = 2) UNION
  SELECT -合计 AS R f ......

经典SQL语句大全

一、基础
1、说明:创建数据库
CREATE DATABASE database-name
2、说明:删除数据库
drop database dbname
3、说明:备份sql server
--- 创建 备份数据的 device
USE master
EXEC sp_addumpdevice 'disk', 'testBack', 'c:\mssql7backup\MyNwind_1.dat'
--- 开始 备份
BACKUP DATABASE pubs TO testBack
4、说 ......

获取SQL Server所有数据库名,表名,字段名


/*
 * Source URL: http://jonsion.javaeye.com/blog/511584
 */
1. 获取所有数据库名
1> SELECT name from master..sysdatabases;
2> go
2. 获取所有表名
1> USE master
2> go
1> SELECT name from sysobjects WHERE type='U';
2> go
3. 获取所有字段名
1> SELECT name ......

SQL精华收集

order by 的数值型灵活使用
select * from table_a where id=p_id order by decode(函数,'asc',1,'desc',-1)*jsny;
控制试图的访问时间:
6.create view ...
as
select ... from where exists(select x from dual where sysdate>=8:00am and sysdate<=5:00pm)
妙用decode实现排序
select * from tabnam ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号