isolating a sub-string in a string before a symbol in SQL Server 2008
DECLARE @dd VARCHAR(200) = 'Net Operating Loss - 2007';
SELECT SUBSTRING(@dd, 1, CHARINDEX('-', @dd) -1) F1,
SUBSTRING(@dd, CHARINDEX('-', @dd) +1, LEN(@dd)) F2
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
This can achieve using two SQL functions- SUBSTRING and CHARINDEX
You can read strings to a variable as shown in the above answers, or can add it to a SELECT statement as below:
SELECT SUBSTRING('Net Operating Loss - 2007' ,0, CHARINDEX('-','Net Operating Loss - 2007'))