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

sql游标

因为要根据很复杂的规则处理用户数据,所以这里用到数据库的游标。平时不怎么用这个,写在这里纯粹为自己备个忘。
--将学籍号重复的放入临时表 tmp_zdsoft_unitive_code(除高中学段外)
drop table tmp_zdsoft_unitive_code;
select s.id ,sch.school_code,sch.school_name,s.student_name,s.unitive_code,s.identity_card,
c.section,c.acadyear,c.class_name ,s.now_state
INTO tmp_zdsoft_unitive_code
from student_info as s ,basic_schoolinfo as sch
,basic_class as c where s.unitive_code in(
select unitive_code from student_info where len(unitive_code)>0 and isdeleted='0' group by  unitive_code having count(1)>1
) and c.section<>3 and s.isdeleted='0' and s.school_id=sch.id and s.class_id=c.id order by unitive_code,student_name
--建立临时表
drop table tmp_zdsoft_stuid;
create table tmp_zdsoft_stuid(id varchar(32) not null);
--利用三层游标,检索学籍号相同,姓名身份证都不同的学生,存放到临时表tmp_stuid
declare @unitive_code  varchar(30),
  @student_name varchar(60),
  @identity_card  varchar(18),
  @stuid  varchar(36)
--检索学籍号重复的学生---
declare tmp_cursor cursor for 
  select unitive_code,student_name,identity_card,id from tmp_zdsoft_unitive_code
  
OPEN tmp_cursor
FETCH next from tmp_cursor into @unitive_code,@student_name,@identity_card,@stuid
while @@fetch_status = 0
begin
 begin
 
--------------内层循环(检验姓名在同学籍号是否唯一)----------------------------
declare @count_name  int
    
declare tmp_cursor2 cursor for 
  select count(1) from tmp_zdsoft_unitive_code
  where unitive_code = @unitive_code and student_name=@student_name and (len(identity_card)=0 or isnull(identity_card,'')='')
OPEN tmp_cursor2
FETCH next from tmp_cursor2 into @count_name
while @@fetch_status = 0
begin
 begin
  if @count_name =1
  begin
   insert into tmp_zdsoft_stuid values(@s


相关文档:

SQL中一些简单但常用的东西汇总下


In:等值连接,用来查找多表相同字段的记录
Not In:非等值连接,用来查找不存在的记录
Inner join:内连接,主要用来查找都符合条件的记录
Left join:左连接,主要用来查找左边有,右边没有的用空值表达
Right join:右连接,主要用来查找右边有,左边没有的用空值表达
Order By:升序 Asc 降序 Desc
Group By:分组排序 ......

SQL大全

 
SQL 命令
这部分包含那些 PostgreSQL 支持的 SQL 命令的信息.这里的 "SQL" 就是该语言通常的含义; 每条命令的与标准有关的兼容性的信息可以在相关的参考页中找到.
Table of Contents
ABORT --  退出当前事务
ALTER GROUP --  向组中增加用户或从组中删除用户 
ALTER USER --&nb ......

pl plus执行本地的sql文件中的sql语句


功能:pl plus执行本地的sql文件中的sql语句
说明:比如:e:\zhaozhenlong下有create_table.sql文件,则按如下方法执行:
步骤:
1、在pl plus的 window下,
 
2、执行:
@e:\zhaozhenlong\drop_table.sql
@e:\zhaozhenlong\create_table.sql
......

SQL Server死锁总结

1. 死锁原理
    根据操作系统中的定义:死锁是指在一组进程中的各个进程均占有不会释放的资源,但因互相申请被其他进程所站用不会释放的资源而处于的一种永久等待状态。
    死锁的四个必要条件:
互斥条件(Mutual exclusion):资源不能被共享,只能由一个进程使用。
请求与保持条件(Ho ......

sql 执行顺序

SQL Select语句完整的执行顺序
2009-06-02 15:57
SQL Select语句完整的执行顺序:1、from子句组装来自不同数据源的数据;2、where子句基于指定的条件对记录行进行筛选;3、group by子句将数据划分为多个分组;4、使用聚集函数进行计算;5、使用having子句筛选分组;
以下结论是通过在Sql Server2000上的实验得出的结论, ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号