zoukankan      html  css  js  c++  java
  • SqlServer如何判断字段中是否含有汉字?

    --/* 
    --unicode编码范围: 
    --汉字:[0x4e00,0x9fa5](或十进制[19968,40869]) 
    --数字:[0x30,0x39](或十进制[48, 57]) 
    --小写字母:[0x61,0x7a](或十进制[97, 122]) 
    --大写字母:[0x41,0x5a](或十进制[65, 90]) 
    --根据编码范围来判断 
    --*/
    --创建
     
    create proc p_A_VIC 
    as 
    declare @count int 
    declare @i int 
    declare @text nvarchar(50) 
    set @i = 0
    set @count = (select COUNT (*) from table  )
    while(@i < @count )
    begin
        set @i +=1
        --sid代表有一定循环规律的,若是无序的可以添加一个序列(Row_Number() OVER ---)。
        --select * from (SELECT *, Row_Number() OVER ( ORDER BY [sid] ) num FROM s--table ) as s where num = 3
        set @text = (select  a from table  where [sid] = @i)
        if unicode(@text) between 19968 And 40869 or unicode(@text) between 97 And 122 or unicode('a') between 65 And 90
        begin
          print 0
        end
        else
           print @text
    end
    --执行 
    exec  p_A_VIC

    实例1:

    ---由于某些原因HouseName 字段存入了GUID,为了区分
    SELECT HouseName FROM ZSGYTD_HouseInfo 
    SELECT HouseName FROM ZSGYTD_HouseInfo WHERE UNICODE(HouseName) BETWEEN 19968 AND 40869

    执行结果:

    实例2:

    ----将上述存入ZSGYTD_Estate 表ID的houseName进行左连接,获取到对应的Name
    SELECT h.HouseName,
    CASE WHEN UNICODE(h.HouseName) BETWEEN 19968 AND 40869 then h.HouseName 
         ELSE e.Name
         END housename2    
    FROM ZSGYTD_HouseInfo  h
    LEFT JOIN ZSGYTD_Estate e ON CONVERT(varchar(50),e.ID)=h.HouseName and e.IsDeleted=0 
    
    
    select*from ZSGYTD_Estate

    执行结果:

  • 相关阅读:
    day10T3改错记
    day9T1改错记
    day8T1改错记
    洛谷P5068[Ynoi2015]我回来了(bfs+bitset)
    BZOJ4939[Ynoi2016]掉进兔子洞(莫队+bitset)
    [学习笔记]dsu on tree
    [学习笔记]FWT(快速沃尔什变换)
    [学习笔记]FMT(快速莫比乌斯变换)&子集卷积(待填坑)
    POJ-1743-Musical Theme(后缀数组)
    后缀数组模板
  • 原文地址:https://www.cnblogs.com/dyhao/p/10072094.html
Copyright © 2011-2022 走看看