解决方案 »

  1.   

    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
      

  2.   


    declare @person_num tinyint,@cno char(5),@tno1 char(6),@tno2 char(6),
     @tno3 int
    问题在你用了char类型,这个char类型会自动在尾部加上空格,所以就会导致有问题,你最好把char(6)修改为varchar(6),这样应该就没问题了
      

  3.   

    select @tno1=tno,@tno3=convert(int,right(@tno1,1))+1 ,@tno2=replace(@tno1,right(@tno1,1),@tno3) from t order by tno
      

  4.   

    你这个地方用RIGHT来截取在从0-9是没问题 超过10了就有问题了。应该用RIGHT(1000000+@TNO1,6)这样截取比较合适。
      

  5.   

    使用RIGHT(1000000+@TNO1,6)显示无法转换成int
      

  6.   

    RIGHT(1000000+@TNO1,6的结果是啥?
      

  7.   

    结果出不来,就显示错误信息,不能把varchar转化为int类型
      

  8.   

    DECLARE @a VARCHAR(10)
    SET @a='T3'
    SELECT 'T'+CAST(SUBSTRING(@A,2,LEN(@A))+1 AS VARCHAR)/*
    -------------------------------
    T4*/
    如果只是第一个字符是字母的话,可以用这个方法试试: