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

    执行结果:

  • 相关阅读:
    1、编写一个简单的C++程序
    96. Unique Binary Search Trees
    python 操作redis
    json.loads的一个很有意思的现象
    No changes detected
    leetcode 127 wordladder
    django uwsgi websocket踩坑
    you need to build uWSGI with SSL support to use the websocket handshake api function !!!
    pyinstaller 出现str error
    数据库的读现象
  • 原文地址:https://www.cnblogs.com/dyhao/p/10072094.html
Copyright © 2011-2022 走看看