SELECT @no1_char = [first] FROM mybestTable WHERE id_num = @i
select @no1_char --看看@no1_char是否为 胜      IF ( '胜' = LTRIM(RTRIM(@no1_char)) )
         SET @no1 = 1
      ELSE
         SET @no1 = 0

解决方案 »

  1.   

    to WangZWang(阿来) 
    请问大哥:你的意思就是仅仅需要增加一句select @no1_char吗?
      

  2.   

    create table mybesttable (id char(2),[first] char(10))insert into mybesttable select '1','胜'
    union all select '2','败'select * from mybesttabledeclare @no1_char char(10)declare @no1 bit
    SELECT @no1_char = [first] FROM mybestTable WHERE id = '1'
    select @no1_char     IF ( '胜' = LTRIM(RTRIM(@no1_char)) )
             SET @no1 = 1
          ELSE
             SET @no1 = 0select @no1
    胜        1
      

  3.   

    create table mybesttable (id_num char(2),[first] char(10))insert into mybesttable select '1','胜'
    union all select '2','败'
    create function dbo.f_dd(@i char(2))
    returns bit
    as 
    begindeclare @no1_char char(10)
    declare @no1 bit
    select @no1_char= [first] FROM mybestTable WHERE id_num= @i
    select @no1=case when ltrim(rtrim(@no1_char))='胜' then 1 else 0 endreturn(@no1)
    end
    select id_num,dbo.f_dd(id_num) from mybesttable
    drop table mybesttable
    drop function dbo.f_dd