查询,仅从字符串中获取数字。假设我有这样的数据:string 1: 003Preliminary Examination Plan string 2: Coordination005
string 3: Balance1000sheet我期望的输出是string 1: 003string 2: 005string 3: 1000我想在SQL中实现它。请帮帮忙。(预先谢谢:)
3 回答
喵喔喔
TA贡献1735条经验 获得超5个赞
UDF
CREATE FUNCTION dbo.udf_GetNumeric(@strAlphaNumeric VARCHAR(256))RETURNS VARCHAR(256)ASBEGINDECLARE @intAlpha INTSET @intAlpha = PATINDEX('%[^0-9]%', @strAlphaNumeric)BEGINWHILE @intAlpha > 0BEGINSET @strAlphaNumeric = STUFF(@strAlphaNumeric, @intAlpha, 1, '' )SET @intAlpha = PATINDEX('%[^0-9]%', @strAlphaNumeric ) ENDENDRETURN ISNULL(@strAlphaNumeric,0)ENDGO
function
SELECT dbo.udf_GetNumeric(column_name) from table_name
添加回答
举报
0/150
提交
取消