如何获取字符串的长度并确保它在Sql查询中是数字的 [英] How Do I Get The Length Of A String And Ensure It Is Numeric In Sql Query
本文介绍了如何获取字符串的长度并确保它在Sql查询中是数字的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好b $ b
我的数据会插入到我的表格中的列中。
我想知道我可以运行哪个脚本来查看该列中的数据是否为10个字符,并且是一个数字?
Hi
I have data which gets inserted into a column in my table.
I would like to know what script could i run to see if the data in that column is 10 Characters in length and it is a number?
推荐答案
use SQL LEN [ ^ ]用于查找字符串的长度并且 IsNumeric [ ^ 检查它是否是一个数字。
样品:
use SQL LEN[^] for finding the length of a string and IsNumeric[^] for checking it is a number or not.
Sample:
declare @value varchar(25)
set @value = '23423443453'
if( LEN(@value) = 10)
if ( ISNUMERIC (@value) =1)
select @value + '--is a number'
else
select 'not a number'
else
select 'not a 10 digit number'
这篇关于如何获取字符串的长度并确保它在Sql查询中是数字的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文