sql查询修剪数值 [英] sql query to trim numerical value

查看:162
本文介绍了sql查询修剪数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好.

尝试从下面的文本中修剪一个值

开奖日期DATE 2014-05-23,唯一编号:B935036.使用飞行中心赢得3个R100 000假期中的1个.请在18h25抽奖日期观看天空电视. T和C的

我想要的值是B935036

我一直在尝试以下

TRIM(从REPLACE跟踪(REPLACE(SUBSTRING(m.`Message`,LOCATE(``Win'',m.`Message`)),LOCATE(''Draw DATE 2014-05-23,UNIQUE number:'',m .`Message`)-LOCATE(``Win'',m.`Message`)),``\ n'',``''),``\ t'',``'')))AS输入

但我似乎做对了.

请帮助

Hi Everyone.

trying to trim a value from the text below

Draw DATE 2014-05-23, UNIQUE number: B935036. Win 1 of 3 R100 000 holidays WITH Flight Center. Watch sky tv ON draw DATE AT 18h25. T''s and C''s

the value that i want is B935036

I have been trying the following

TRIM(TRAILING FROM REPLACE(REPLACE(SUBSTRING(m.`Message`, LOCATE(''Win'', m.`Message`), LOCATE(''Draw DATE 2014-05-23, UNIQUE number:'', m.`Message`) - LOCATE(''Win'', m.`Message`)), ''\n'', ''''), ''\t'', '''')) AS Entry

but i cant seem to get it right.

Please help

推荐答案

SQL具有CHARINDEX函数,所以我要做的是使用SUBSTRING来获取冒号和点之间的部分:
SQL has the CHARINDEX function, so what I would do is use SUBSTRING to fetch the part between the colon and the dot:
DECLARE @STR NVARCHAR(MAX)
SET @STR = 'Draw DATE 2014-05-23, UNIQUE number: B935036. Win 1 of 3 R100 000 holidays WITH Flight Center. Watch sky tv ON draw DATE AT 18h25. T''s and C''s '
SELECT SUBSTRING(@STR, CHARINDEX(':', @STR) + 2, 7)


这篇关于sql查询修剪数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆