DECLARE @test varchar(100)
SET @test=''
if charindex('',@test)>0
set @test='x'
上面的查询不显示‘x'
1. 什么原因?如何显示‘x'2 上面的@test是空字符串(里面没有空格),同’   ‘(有三个空格)是否相同?

解决方案 »

  1.   

    1.
    DECLARE @test varchar(100)
    SET @test=''
    if charindex('',@test)>=0
    set @test='x'
    print @test2.
    bu xiang tong
      

  2.   

    DECLARE @test varchar(100)
    SET @test='x'select charindex('',@test)
    -- the result is also 0
    --I need that WHEN ''
    --THEN 'x'
    --ELSE  'xxx'
      

  3.   

    DECLARE @test varchar(100)
    SET @test=''
    if charindex('',@test)>0   ----charindex鏄釜鍒ゆ柇瀛楃鐨勫嚱鏁帮紝瀛楃閮芥病鏈夋€庝箞鍒ゆ柇锛?
    set @test='x'    ---娌¤繍琛岃繖鍙?
    2銆傜┖鏍间笉绛変簬鏃犲€硷紒锛?  NULL涓嶇瓑浜庘€?鈥
      

  4.   

    zen mo shi luan ma a!!
      

  5.   

    DECLARE @test varchar(100)
    SET @test='x'select charindex('',@test)
    结果0DECLARE @test varchar(100)
    SET @test=''select charindex('',@test)
    结果0
    如何检测字符中的空字符串当只有''时候(当中没有空格)时候显示‘x'
    其他显示’y'(包括‘    ’也显示‘y')
      

  6.   

    直接判断@test='',不要用charindex
      

  7.   

    DECLARE @test varchar(100)
    SET @test=''
    IF @test=''
    select 1结果 1DECLARE @test varchar(100)
    SET @test='   '
    IF @test=''
    select 1
    结果 1
      

  8.   

    DECLARE @test varchar(100)
    SET @test=''
    IF @test=''
    select 1结果 1DECLARE @test varchar(100)
    SET @test='   '
    IF @test=''
    select 1
    结果 1
    那么上面的例子如何,使它根据‘’,和‘   ’
    返回不同的结果?