sql server - SQL to retrieve first sentence from a block of text -
i have following sql sql server:
declare @summary1 nvarchar(max) declare @summary2 nvarchar(max) set @summary1='this long text. rest of text' set @summary2='some text no full stops' select substring(@summary1, 1,charindex('.', @summary1)) sentence select substring(@summary2, 1,charindex('.', @summary2)) sentence
i want able first sentence "summary" , if there no full stop return text. example @summary1 works fine no full stop in text nothing returned.
anyone have bright ideas how can achieve this?
i use case
expression:
select case charindex('.', @summary1) -- determine if sentence contains full stop when 0 @summary1 -- if not return whole sentence else substring(@summary1, 1, charindex('.', @summary1)) -- else first part end sentence
Comments
Post a Comment