易截截图软件、单文件、免安装、纯绿色、仅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 Server 日期格式化函数

Sql Server 中一个非常强大的日期格式化函数
Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM
Select CONVERT(varchar(100), GETDATE(), 1): 05/16/06
Select CONVERT(varchar(100), GETDATE(), 2): 06.05.16
Select CONVERT(varchar(100), GETDATE(), 3): 16/05/06
Select CONVERT(varchar(100), GE ......

利用pl/sql执行本地的sql文件中的sql语句


功能:pl/sql执行本地的sql文件中的sql语句
说明:比如:e:\zhaozhenlong下有create_table.sql文件,则按如下方法执行:
步骤:
1、在pl/sql的command window下,
   或在windows的开始/'运行'下,sqlplus /nolog; connect cs@orademo;
2、执行:
@@e:\zhaozhenlong\drop_table ......

SQL Server死锁总结

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

数据库行转列的sql语句(转)


数据库行转列的sql语句
问题描述
假设有张学生成绩表(CJ)如下
Name Subject Result
张三 语文 80
张三 数学 90
张三 物理 85
李四 语文 85
李四 数学 92
李四 物理 82
现在 想写 sql 语句     查询后结果 为    
姓名 语文 数学 物理
张三 80 90 85
李四 85 92 82& ......

sql函数常用函数

1.     select replace(CA_SPELL,' ','') from hy_city_area  去除列中的所有空格
2.     LTRIM() 函数把字符串头部的空格去掉
3.     RTRIM() 函数把字符串尾部的空格去掉
4.     select LOWER(replace(CA_SPELL,' ','')) f ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号