我试图从字符串中提取一个子字符串(在这种情况下,连字符之前的所有内容),如下所示:
Net Operating Loss - 2007 Capital Loss - 1991 Foreign Tax Credit - 1997
并想要年份和名称(连字符之前的子串)分开使用sql Server Management Studio 2008.任何建议?或想法如何实现这一点?
解决方法
DECLARE @test nvarchar(100) SET @test = 'Foreign Tax Credit - 1997' SELECT @test,left(@test,charindex('-',@test) - 2) AS LeftString,right(@test,len(@test) - charindex('-',@test) - 1) AS RightString