tags:

views:

28

answers:

2

I have some data that I needs to be searched for the comma character.

example entry I need to locate in the field Citation in the Citations table: This is sometimes true, Textual Reference

In the end, I'm looking to extract Textual Reference

Selecting the column with the data:

select Citation from Citations;
A: 

This works to select the data, but doesn't isolate what I want:

SELECT        Citation
FROM            Citations
WHERE        (Citation LIKE '%\,%' ESCAPE '\')
ORDER BY Citation

Ah, this works:

    SELECT Citation,
           SUBSTRING(Citation,
              CHARINDEX(',', Citation) + 1,
              LEN(Citation) - CHARINDEX(',', Citation)) AS Truncated
    FROM            Citations
    WHERE        (Citation LIKE '%\,%' ESCAPE '\')
    ORDER BY Truncated

Thanks ck!

Fred
A: 

Try something like this:

SELECT        Citation
          , SUBSTRING(Citation, CHARINDEX(',', Citation) + 1, 
                      LEN(Citation) - CHARINDEX(',', Citation))
FROM            Citations 
WHERE        (Citation LIKE '%\,%' ESCAPE '\') 
ORDER BY Citation 
ck
syntax doesn't error out, but the two columns are identical.
Fred