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).
精彩评论