开发者

Parse this string

开发者 https://www.devze.com 2023-03-08 04:07 出处:网络
What are the other ways to we parse this: DECLARE @t AS TABLE(DESCRIPTION NVARCHAR(50)) INSERT INTO @t(DESCRIPTION)

What are the other ways to we parse this:

DECLARE @t AS TABLE(DESCRIPTION NVARCHAR(50))

INSERT INTO @t(DESCRIPTION)

SELECT '1/8 qwe dfg asd asd' UNION ALL

SELECT '1/2 dfg asd qwe asd' UNION ALL

SELECT '1/2 asd dfg qwe asd' UNION ALL

SELECT '1/2 qwe asd asd rtq'

SELECT * FROM @t
开发者_Python百科

/* Output : */

--1/8 qwe

--1/2 dfg

--1/2 asd

--1/2 qwe

Don't use fixed lenght, maybe charindex or something :)


How about:

substring (description,
           1,
           charindex (' ',
                      description,
                      charindex(' ', description)+1
                     )-1
          )

(I can't test it as I don't have access to SQL Server).

0

精彩评论

暂无评论...
验证码 换一张
取 消