首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

-帮小弟我修改一下-

2012-01-10 
-------帮我修改一下---------- address-----------------------01四川省02北京市03天津市……-------------

-------帮我修改一下----------

address    
-----------------------    
01             四川省    
02             北京市    
03             天津市    
……    
-----------------------    
subject    
-----------------------    
01                     施工员    
02                     预算员    
03                     资料员    
……    
-----------------------    
kd
-----------------------
id       kd
11       1号考场
12       2号考场
13       3号考场
14       4号考场
15       5号考场
16       6号考场
-----------------------
enter    
-----------------------    
name                   subject     address       kd         examnumber    
王1                     施工员         天津市       11         03110100001    
王2                     预算员         北京市       12         02120200001    
王3                     预算员         北京市       12         02120200002    
王4                     施工员         四川省       13         02130100001    
王5                     施工员         四川省       13         02130100002    
王6                     资料员         天津市       14         03140300001    
王7                     资料员         天津市       14         03140300002    
王8                     预算员         天津市       15         03150200001    
王9                     预算员         天津市       15         03150200002    
王10                   预算员         四川省       16         02160200001
------------------------    
现在表里面的examnumber     全是空的。    
原来是没有考点,只是:   地址+科目+5位排序号  
代码如下:
update   e
set     examnumber   =a.addressid+s.subjectid+right(100000+(select   count(*)   from   enter   where   address=e.address   and   subject=e.subject   and   name <=e.name),5)
from           enter   e,gw_subject   s,gw_address   a


where         e.subject=   s.subject   and   e.address=a.addressname

但是现在加入了考场2位数字。
求高手帮忙修改一下。
应该怎样来修改这条语句才能正确的显示。
达到要求:地址+考场+科目+5位排序号。判断级别是从左--右。




[解决办法]
update e
set examnumber =a.addressid+cast(e.kd as varchar)+s.subjectid+right(100000+(select count(*) from enter where address=e.address and subject=e.subject and kd=e.kd and name <=e.name),5)
from enter e,gw_subject s,gw_address a
where e.subject= s.subject and e.address=a.addressname


[解决办法]
---- 如果你的kd是Int类型的+起来会出问题,需要转换成字符型才可以相加
----Try:
update e
set examnumber =a.addressid+Cast(e.kd As Varchar)+s.subjectid+right(100000+(select count(*) from enter where address=e.address and subject=e.subject and kd=e.kd and name <=e.name),5)
from enter e,gw_subject s,gw_address a
where e.subject= s.subject and e.address=a.addressname

热点排行