-1

实际上有2个问题,2个疑问:

  • 我需要找出一个以 long 开头的数字'541'事实上18 chars在 SO 之后有一个空格:Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when....'541'....15RandomNumbers in (0,1,2,3,4,5,6,7,8,9).....an unknown printer took a galley of type and scrambled it to make a type specimen book.
  • 第二:检查字符串的最后 18 个字符是否为数字(可能在修剪后)

而已,

4

2 回答 2

2

“找出以 '541' 开头的数字是 18 个字符长”

( text_col NOT LIKE '541%' OR LEN(text_col) = 18 )

“检查字符串的最后 18 个字符是否为数字(可能在修剪后)”

   ( RTRIM(text_col) LIKE '%[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]' )
于 2012-04-17T09:50:06.367 回答
1

一些数据让你开始

declare @tmp table (value nvarchar(30))
insert @tmp values ('ABC123456789123456789'),('ABC12345678912345678A'),('ABC123456789123456D78')

RIGHTISNUMERIC

SELECT t.value, ISNUMERIC(RIGHT(t.value,18)+'.0e0') as [IsNumeric]
FROM @tmp t

给出:

value                          IsNumeric
------------------------------ -----------
ABC123456789123456789          1
ABC12345678912345678A          0
ABC123456789123456D78          0

编辑:我已经根据反馈修改了我的答案,Damien_The_Unbeliever并解决了他提出的问题

于 2012-04-17T09:47:17.043 回答