create proc Check
@id int,
@type varchar(16)
asif(@type.equals("1"))         ------这里应该怎么写?
  begin
      select * from Student where classID = @id
  end
else
  begin
     select * from Student where gradeID = @id
  end
SQL里面字符串的比较怎么写?

解决方案 »

  1.   

    if @type='1'        
      

  2.   

    消息 207,级别 16,状态 1,过程 Test,第 8 行
    列名 '1' 无效。
      

  3.   


    create proc Check 
    @id int, 
    @type varchar(16) 
    as 
    begin
     if(@type=1)         begin 
          select * from Student where classID = @id 
      end 
     else 
      begin 
        select * from Student where gradeID = @id 
      end 
    end
      

  4.   

    create proc [Check] 
    @id int, 
    @type varchar(16) 
    as if(@type='1')        ------这里应该怎么写? 
      begin 
          select * from Student where classID = @id 
      end 
    else 
      begin 
        select * from Student where gradeID = @id 
      end 
      

  5.   


    create proc Check 
    @id int, 
    @type varchar(16) 
    as 
    begin
     if(@type=1)         
      begin 
          select * from Student where classID = @id 
      end 
     else 
      begin 
        select * from Student where gradeID = @id 
      end 
    end这么写就是对的,但是如果你的@type是由数字组成的话,加上单引号的话也是对的,(if @type=‘1’)
    就看你的参数类型是什么了。如果是字符串,那么必须是用单引号的。
      

  6.   

    @type=1(数字型)
    @type='1'(非数字型)sql 里面比较 没有c#的== 和 Java的equals!