开发者

How do I search for the comma character within data stored in SQL Server?

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

example entry I need to locate in the field Cita开发者_Go百科tion 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;


Try something like this:

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


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!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜