我需要按照一些规则给我写一个SEO朋友格式的歌曲标题。SQL Server:字符串操作来写出搜索引擎优化友好标题
最大lentgh是52个字符。目前截断发生在以CL开始的记录上,并且与一组关联ID有关。
额外的规则我要申请是:
- 如果seo_friendly_title以结束“ - ”将其删除。
- 如果 截断在单词或空格的中间结束,则移至下一空格(下一个单词的结尾) 。
我想我必须添加嵌套的CASE
语句才能完成此操作,但我不知道在哪里添加这个新检查。
我想请求你帮忙完成这个算法,希望有人可以分享他们的经验,并展示/解释如何做到这一点。
非常感谢。
这里是我当前的SQL查询:
SELECT
[sfwt].[seo_friendly_title]
, CASE
WHEN [sfwt].[pf_id] LIKE 'CL%' AND [pd].[AssociationID] IN (1, 3, 4) THEN
LEFT([sfwt].[seo_friendly_title], 52)
END [seo_final_title]
FROM
[dbo].[SEOFriendly_WorkingTable] [sfwt]
INNER JOIN [dbo].[ProductData] [pd]
ON [pd].[ProductID] = [sfwt].[pf_id]
WHERE [sfwt].[pf_id] LIKE 'CL%'
ORDER BY
[sfwt].[pf_id];
和输出:
seo_friendly_title seo_final_title
prelude-no-5-for-trumpet-and-piano-johann-sebastian-bach prelude-no-5-for-trumpet-and-piano-johann-sebastian-
prelude-no-8-for-trumpet-and-piano-johann-sebastian-bach prelude-no-8-for-trumpet-and-piano-johann-sebastian-
highlights-from-the-lord-of-the-rings-the-return-of-the-king highlights-from-the-lord-of-the-rings-the-return-of-
air-ecossais-spirituoso-e-marciale-opus-107-no-10-f-instrument-piano air-ecossais-spirituoso-e-marciale-opus-107-no-10-f-
air-ecossais-spirituoso-e-marciale-opus-107-no-10-c-instrument-piano air-ecossais-spirituoso-e-marciale-opus-107-no-10-c-
air-de-la-petite-russie-opus-107-no-3-bb-instrument-piano air-de-la-petite-russie-opus-107-no-3-bb-instrument-
air-de-la-petite-russie-opus-107-no-3-eb-instrument-piano air-de-la-petite-russie-opus-107-no-3-eb-instrument-
shell-be-coming-round-the-mountain-c-instrument-and-piano shell-be-coming-round-the-mountain-c-instrument-and-
shell-be-coming-round-the-mountain-f-instrument-and-piano shell-be-coming-round-the-mountain-f-instrument-and-
9-ecossaises-from-38-waltzer-landler-und-ecossaisen-op-18 9-ecossaises-from-38-waltzer-landler-und-ecossaisen-
我打算用这个作为出发点,当我取得进展时,我可能会提出一个新问题。谢谢拉胡尔。 –