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

          與我一起遨游吧

           

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

          --數據裝載
          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 閱讀(170) 評論(0)  編輯  收藏


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


          網站導航:
           

          導航

          統計

          常用鏈接

          留言簿(2)

          隨筆分類

          隨筆檔案

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 盘锦市| 贵溪市| 淮安市| 东城区| 邮箱| 江孜县| 安图县| 自贡市| 塘沽区| 会昌县| 安塞县| 凤翔县| 林周县| 斗六市| 高雄市| 东城区| 乌苏市| 彰化县| 英吉沙县| 商洛市| 威信县| 衡东县| 松阳县| 陵川县| 玉溪市| 长岭县| 秦安县| 芦溪县| 泾源县| 修水县| 炉霍县| 青冈县| 大方县| 体育| 郑州市| 临沧市| 江孜县| 湖州市| 大埔县| 谢通门县| 阜宁县|