簡體   English   中英

如何執行SQL查詢以在僅6個字符長且以5開頭的字段中查找數字?

[英]How do I do a SQL query that finds numbers in a field that is only 6 characters long and starts with the number 5?

請參見以下代碼:

select no_
from dbo.customer
where no_ like '5%%%%%'

采用:

select no_ from dbo.customer where no_ like '5_____'

LIKE運算符可識別兩個通配符:

  • %-百分號代表零個,一個或多個字符
  • _-下划線表示單個字符

好吧,你會這樣做:

 select no_ from dbo.customer where no_ like '5%'

%是通配符,可匹配任意數量的字符,包括無字符。

如果您也想保證6個字符:

 select no_ from dbo.customer where no_ like '5_____'

_是一個完全匹配一個字符的通配符。

我也將添加數字

select no_ from dbo.customer where no_ like '5_____' and ISNUMERIC(no_) = 1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM