六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 51|回复: 0

如何安装考场

[复制链接]

升级  36.35%

563

主题

563

主题

563

主题

探花

Rank: 6Rank: 6

积分
1727
 楼主| 发表于 2013-2-7 14:45:51 | 显示全部楼层 |阅读模式
有一表:
编号 考号 姓名
1 cc01 AA
1 cc02 BB
1 cc03 CC
1 cc04 DD
1 cc05 EE
...
我的目的就是根据每个考室的人数(用户输入)自动生成一个表,如按一个考室3个考生的效果如下:
考室 考号区间
1  cc01-cc03
2  cc04-cc05
--------------------
create table tb(编号 int,考号 char(4),姓名 varchar(10))insert tb select 1 ,  'cc01' , 'AA' insert tb select 1 ,  'cc02' , 'BB' insert tb select 1 ,  'cc03' , 'CC' insert tb select 1 ,  'cc04' , 'DD' insert tb select 1 ,  'cc05' , 'EE'goselect ceiling(cnt/3.0) row,* into tfrom (   select *,cnt=(select count(*) from tb where 考号<=a.考号)   from tb a) ttgocreate function dbo.f_str(@row int)   returns varchar(100)asbegin   declare @re varchar(100)   set @re=''   select top 1 @re=考号 from t where row=@row order by 考号   select top 1 @re=@re+'-'+考号 from t where row=@row order by 考号 desc   return @reendgoselect row [室号],dbo.f_str(row) [考号区间]from tgroup by rowdrop table tb,tdrop function f_str/*室号                        考号区间-------------------- --------------1                      cc01-cc032                      cc04-cc05(2 行受影响)*/http://topic.csdn.net/u/20080305/18/34a9f481-1dac-43bf-9bde-d21d2ba75880.html?seed=1637030877
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表