I am trying to populate our "short description" field using the "full description" field. Basically, I want to set the ShortDescription
column equal to the first three sentences from the FullDescription
column.
I know how I would do this in C#, but I am having a little trouble getting it done in my SQL query. I don't care about performance- as this query will only be ran one time to generate this temporary data. So, any and all solutions will work just find for us!
My attempt:
UPDATE Product
SET ShortDescription = (
CASE
WHEN (LEN(FullDescription) - LEN(REPLACE(FullDescription, '.', ''))) >= 3 THEN
(
SELECT
LEFT(str, pos)
FROM (
SELECT
FullDescription AS str,
CHARINDEX('.', FullDescription) AS pos
) x
)
ELSE
FullDescription
END
)
WHERE FullDescription IS NOT NULL;
Unfortunately, the above query only gets the first sentence. I can't seem to figure out how to find the CHARINDEX of the third period. Anyone know a clean and easy way to locate this character?
Also, am I correct in my assumption that the periods are really the only way to identify sentences? I am concerned that (in some rare occasions), that there may be decimals in the sentences, which would provide some awful descriptions like: "This product is great. It has awesome features. It is 2."...
Any direction or feedback is greatly appreciated! Thank you!