注册 登录
编程论坛 SQL Server论坛

数字?怎么定义

胡丽红 发布于 2016-05-24 16:41, 2782 次点击
sql

[此贴子已经被作者于2016-5-24 19:51编辑过]

6 回复
#2
mywisdom882016-05-24 17:25
你是要判断还是要生成?
1、判断
用SUBSTRING(),ISNUMERIC(),CHAR()函数来判断
#3
胡丽红2016-05-24 18:03
回复 2楼 mywisdom88
生成
#4
mywisdom882016-05-24 18:04
declare @s char(5)
declare @r int
declare @i int

set @s='A1012'
if (ascii(substring(@s,1,1))>=65 and ascii(substring(@s,1,1))<=90) or
   (ascii(substring(@s,1,1))>=97 and ascii(substring(@s,1,1))<=122)
    set @r=1
else
    set @r=0

set @i=2
while @i<=5
begin
     if ascii(substring(@s,@i,1))>=48 and ascii(substring(@s,@i,1))<=57
        set @r=@r*1
     else
        set @r=@r*0
     set @i=@i+1
end

if @r>0
select 'the string is ok'
else
select 'the string is not ok'
#5
mywisdom882016-05-24 18:04
以下是引用胡丽红在2016-5-24 18:03:29的发言:

生成

随机生成?
#6
胡丽红2016-05-24 19:26
回复 5楼 mywisdom88
是的
#7
胡丽红2016-05-24 19:37
回复 5楼 mywisdom88
好长啊,我看不懂
1