SQL 判断字段值是否有中文?例这段值:
A列:
ASDKG论坛KDL
KDIO001

解决方案 »

  1.   

    --提取数字
    IF OBJECT_ID('DBO.GET_NUMBER2') IS NOT NULL
    DROP FUNCTION DBO.GET_NUMBER2
    GO
    CREATE FUNCTION DBO.GET_NUMBER2(@S VARCHAR(100))
    RETURNS VARCHAR(100)
    AS
    BEGIN
    WHILE PATINDEX('%[^0-9]%',@S) > 0
    BEGIN
    set @s=stuff(@s,patindex('%[^0-9]%',@s),1,'')
    END
    RETURN @S
    END
    GO
    --测试
    PRINT DBO.GET_NUMBER('呵呵ABC123ABC')
    GO
    --123
    --------------------------------------------------------------------
    --提取英文
    IF OBJECT_ID('DBO.GET_STR') IS NOT NULL
    DROP FUNCTION DBO.GET_STR
    GO
    CREATE FUNCTION DBO.GET_STR(@S VARCHAR(100))
    RETURNS VARCHAR(100)
    AS
    BEGIN
    WHILE PATINDEX('%[^a-z]%',@S) > 0
    BEGIN
    set @s=stuff(@s,patindex('%[^a-z]%',@s),1,'')
    END
    RETURN @S
    END
    GO
    --测试
    PRINT DBO.GET_STR('呵呵ABC123ABC')
    GO
    --------------------------------------------------------------------
    --提取中文
    IF OBJECT_ID('DBO.CHINA_STR') IS NOT NULL
    DROP FUNCTION DBO.CHINA_STR
    GO
    CREATE FUNCTION DBO.CHINA_STR(@S NVARCHAR(100))
    RETURNS VARCHAR(100)
    AS
    BEGIN
    WHILE PATINDEX('%[^吖-座]%',@S) > 0
    SET @S = STUFF(@S,PATINDEX('%[^吖-座]%',@S),1,N'')
    RETURN @S
    END
    GO
    PRINT DBO.CHINA_STR('呵呵ABC123ABC')
    GO
    本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/ws_hgo/archive/2010/03/19/5397145.aspx
      

  2.   

    --得到有中文的
    select * from tb where patindex('%[吖-座]%',col) > 0
      

  3.   

    SELECT * FROM TB WHERE COL LIKE N'%[吖-咗]%' 
      

  4.   


    create   function   fun_getCN(@str   nvarchar(4000))   
      returns   nvarchar(4000)   
      as   
      begin   
      declare   @word   nchar(1),@CN   nvarchar(4000)   
      set   @CN=''   
      while   len(@str)>0   
      begin   
      set   @word=left(@str,1)   
      if unicode(@word)   between   19968   and   19968+20901 
       set   @CN=@CN+@word
      set   @str=right(@str,len(@str)-1)   
      end   
      return   @CN   
      end   select dbo.fun_getCN('ASDKG论坛KDL')
    论坛
    select dbo.fun_getCN('ASDKG論壇KDL')
    論壇
    select dbo.fun_getCN('ASDKDL')
    空字符串
      

  5.   


    create   function   fun_getCN(@str   nvarchar(4000))   
      returns   nvarchar(4000)   
      as   
      begin   
      declare   @word   nchar(1),@CN   nvarchar(4000)   
      set   @CN=''   
      while   len(@str)>0   
      begin   
      set   @word=left(@str,1)   
      if unicode(@word)   between   19968   and   19968+20901 
       set   @CN=@CN+@word
      set   @str=right(@str,len(@str)-1)   
      end   
      return   @CN   
      end   select dbo.fun_getCN('ASDKG论坛KDL')
    论坛
    select dbo.fun_getCN('ASDKG論壇KDL')
    論壇
    select dbo.fun_getCN('ASDKDL')
    空字符串
      

  6.   


    create   function   fun_getCN(@str   nvarchar(4000))   
      returns   nvarchar(4000)   
      as   
      begin   
      declare   @word   nchar(1),@CN   nvarchar(4000)   
      set   @CN=''   
      while   len(@str)>0   
      begin   
      set   @word=left(@str,1)   
      if unicode(@word)   between   19968   and   19968+20901 
       set   @CN=@CN+@word
      set   @str=right(@str,len(@str)-1)   
      end   
      return   @CN   
      end   select dbo.fun_getCN('ASDKG论坛KDL')
    论坛
    select dbo.fun_getCN('ASDKG論壇KDL')
    論壇
    select dbo.fun_getCN('ASDKDL')
    空字符串
      

  7.   

    sql server 2000也能使正则表达式么?