我如何获得逗号之间的子串? [英] How Can I get substring between commas?

查看:84
本文介绍了我如何获得逗号之间的子串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何获得逗号之间的子串?





例如:2013年5月5日星期四



2013年5月5日星期五





我怎么能得到这个月''五月''来自此。

How Can I get substring between commas?


eg: Thursday,May,05,2013

Friday,May,05,2013


how can i get the month ''May'' from this.

推荐答案

试试这个:

Try this:
DECLARE @tbl TABLE (myText NVARCHAR(30))

INSERT INTO @tbl(myText)
VALUES('Friday,May,05,2013')

;WITH cte AS
(
	SELECT LEFT(myText, CHARINDEX(',', myText)-1) AS Word, RIGHT(myText, LEN(myText) - CHARINDEX(',', myText)) AS Remainder
	FROM @tbl
	WHERE CHARINDEX(',', myText)>0
	UNION ALL
	SELECT LEFT(Remainder, CHARINDEX(',', Remainder)-1) AS Word, RIGHT(Remainder, LEN(Remainder) - CHARINDEX(',', Remainder)) AS Remainder
	FROM cte
	WHERE CHARINDEX(',', Remainder)>0
	UNION ALL
	SELECT Remainder AS Word, NULL AS Remainder
	FROM cte
	WHERE CHARINDEX(',', Remainder)=0
)
SELECT *
FROM cte
WHERE Word = 'May'





M关于公用表格式 [ ^ ]。


这比您需要的更多:在SQL IN子句中使用逗号分隔值参数字符串 [ ^ ] - 但它正在执行相同的任务,只是更完整。
This does rather more than you need: Using comma separated value parameter strings in SQL IN clauses[^] - but it''s doing the same task, just a bit more completely.


看看在此代码项目文章 [ ^ ]关于这个问题
Have a look at this code project article[^] on the subject


这篇关于我如何获得逗号之间的子串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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