在Sql Server中拆分字符串函数 [英] Split string function in Sql Server
本文介绍了在Sql Server中拆分字符串函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在SOL Server中,我从ASP.NET获取参数的值@codeName为1023 - Hydrabad
即@codeName =1023 - Hydrabad
我只想要Hydrabad。如何拆分?
In SOL Server, I get the value for the parameter, @codeName as "1023 - Hydrabad" from ASP.NET
ie, @codeName = "1023 - Hydrabad"
I want Hydrabad alone. How to split it?
推荐答案
您可以使用SQL Server的SUBSTRING和CHARINDEX函数:
You can use SQL Server's SUBSTRING and CHARINDEX functions:
DECLARE @codeName VarChar(100)
SET @codeName = '1023 - Hydrabad'
SELECT SUBSTRING(@codeName, CHARINDEX('-', @codeName) + 2, 100)
或在后面的代码中使用适当的类似.NET方法。
or use appropriate similar .NET methods in your code behind.
DECLARE @LongSentence VARCHAR(MAX)
DECLARE @FindSubString VARCHAR(MAX)
SET @LongSentence = 'SQL,SERVER,TUTORIAL'
SET @FindSubString = ','
SELECT (LEN(@LongSentence) - LEN(REPLACE(@LongSentence, @FindSubString, ''))) CntReplacedChars,
(LEN(@LongSentence) - LEN(REPLACE(@LongSentence, @FindSubString, '')))/LEN(@FindSubString) CntOccuranceChars
这对我来说很好
this is working fine for me
Dim paramval As String = "1023 - Hydrabad"
Dim paramvalue() As String = paramval.Split("-")
@codeName = paramvalue(1).ToString()
这篇关于在Sql Server中拆分字符串函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文