开发者

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

开发者 https://www.devze.com 2022-12-29 05:01 出处:网络
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:

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

精彩评论

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

关注公众号