我的空間,寫我所寫,禪我所藏

          與我一起遨游吧

           

          從數據庫中查找數字和中文的數據

          --數據裝載
          Create Table #T(Column1 varchar(20))
          insert #T select '040011'
          union all select '010021'
          union all select '024綜合'
          union all select '021不知道'
          union all select '031不'
          union all select '不3'
          union all select '知道'

          --1:求包含數字,且長度為6的集合(包含了中文)

          select * from #T  where Column1  like '%[0-9]%'  and len(Column1)=6

          --結果
          Column1             
          --------------------
          040011
          010021
          021不知道

          (所影響的行數為 3 行)

          --2:求包含中文,且長度為6的集合(包含了數字)

          select * from #T  where Column1  like '%[^0-9]%'  and len(Column1)=6

          --結果
          Column1             
          --------------------
          021不知道

          (所影響的行數為 1 行)

          --3:求包含數字,且長度為6的集合(不包含中文)

          select * from #T  where Column1 not like '%[^0-9]%'  and len(Column1)=6
          --結果
          Column1             
          --------------------
          040011
          010021

          (所影響的行數為 2 行)

          --4 求所有記錄只用中文的記錄

          select * from #T  where Column1 not like '%[0-9]%' 

          --結果

          Column1             
          --------------------
          知道

          (所影響的行數為 1 行)

          --5.求所有記錄只有數字的記錄

          select * from #T  where Column1 not like '%[^0-9]%' 
          --結果

          Column1             
          --------------------
          040011
          010021

          (所影響的行數為 2 行)
          或者

          select * from #T  where isnumeric(Column1)=1

          --結果

          Column1             
          --------------------
          040011
          010021

           

          --6.查詢數據中那條記錄包含有中文

          select case when Column1 like N'%[啊-座]%' then '包含中文' else '不包含中文' end
          from #T

          --結果

          ----------
          不包含中文
          不包含中文
          包含中文
          包含中文
          包含中文
          包含中文
          包含中文

          (所影響的行數為 7 行)

           

          --7:只查詢數字字段值

          select * from #Twhere patindex('%[^-^0-9]%',Column1 )=0

          --結果

          Column1             
          --------------------
          040011
          010021

          (所影響的行數為 2 行)

          --8:只查詢中文字段值
          select * from #T where patindex('%[^-^啊-座]%',Column1)=0

          --結果

          Column1             
          --------------------
          知道

           

          Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1505712

          posted on 2007-06-11 12:33 imcb 閱讀(166) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發表評論。


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 东光县| 武乡县| 隆回县| 内江市| 呼玛县| 犍为县| 海原县| 时尚| 双辽市| 兴隆县| 阜康市| 吉首市| 化德县| 黄陵县| 金山区| 论坛| 颍上县| 关岭| 茶陵县| 老河口市| 镇巴县| 浮山县| 正宁县| 密山市| 鹿邑县| 平凉市| 和静县| 张北县| 罗山县| 资溪县| 什邡市| 年辖:市辖区| 南澳县| 板桥市| 中西区| 鲁甸县| 江永县| 南召县| 锦州市| 博客| 长顺县|