begin transaction go use jxsk go declare @person_num tinyint,@cno char(5),@tno1 char(6),@tno2 char(6), @tno3 int select @cno=cno from c where cn='数据结构' select @person_num=count(*) from tc where cno=@cno if @person_num>=2 begin/*不能招聘*/ rollback transaction/*回滚事务*/ print '因数据结构课程的任课人数已满,故程前教师不能在应聘该课程岗位' end else begin/*接受应聘*/ /*计算程前教师的教师号*/ select @tno1=tno from t order by tno select @tno3=convert(int,right(@tno1,1))+1 select @tno2=replace(@tno1,right(@tno1,1),@tno3) /*把教师基本信息插入表T中*/ insert into t(tno,tn,sex,prof,dept) values(@tno2,'程前','男','副教授','计算机') /*把教师任课信息插入授课表TC中*/ insert into tc(tno,cno) values(@tno2,@cno) commit/*提交事务*/ print '程前教师任聘数据结构课程成功!' end go
go
use jxsk
go
declare @person_num tinyint,@cno char(5),@tno1 char(6),@tno2 char(6),
@tno3 int
select @cno=cno from c where cn='数据结构'
select @person_num=count(*) from tc where cno=@cno
if @person_num>=2
begin/*不能招聘*/
rollback transaction/*回滚事务*/
print '因数据结构课程的任课人数已满,故程前教师不能在应聘该课程岗位'
end
else
begin/*接受应聘*/
/*计算程前教师的教师号*/
select @tno1=tno from t order by tno
select @tno3=convert(int,right(@tno1,1))+1
select @tno2=replace(@tno1,right(@tno1,1),@tno3)
/*把教师基本信息插入表T中*/
insert into t(tno,tn,sex,prof,dept) values(@tno2,'程前','男','副教授','计算机')
/*把教师任课信息插入授课表TC中*/
insert into tc(tno,cno) values(@tno2,@cno)
commit/*提交事务*/
print '程前教师任聘数据结构课程成功!'
end
go
declare @person_num tinyint,@cno char(5),@tno1 char(6),@tno2 char(6),
@tno3 int问题在你用了char类型,这个char类型会自动在尾部加上空格,所以就会导致有问题,你最好把char(6)修改为varchar(6),这样应该就没问题了
SET @a='T3'
SELECT 'T'+CAST(SUBSTRING(@A,2,LEN(@A))+1 AS VARCHAR)/*
-------------------------------
T4*/
如果只是第一个字符是字母的话,可以用这个方法试试: