sql - 文本包含两个连字符时的 SQL SERVER 情况
问题描述
我在写案例时遇到了问题。如果一个文本中有两个连字符,我如何在 sql server 语句中写一个 case 表达式?
行值如下:
PA-PB-PC(2 个连字符)
PA-PAC(1 个连字符)
期望的结果将是这样的
Case when (section text contains two hyphens) then isnull(parsename(replace
(ResponsibleSection,'-','.'),2) else isnull(parsename(replace
(ResponsibleSection,'-','.'),1)
这是我原来的问题代码: -
select ResponsibleSection = isnull(parsename(replace
(ResponsibleSection,'-','.'),2),Section) from FeedbackOwnerSetting
Group by ResponsibleSection
对此有任何想法吗?
解决方案
使用模式匹配:
CASE WHEN YourColumn LIKE '%-%-%' THEN [True Expression] ELSE [False Expression] END
推荐阅读
- c++ - 在 Opengl 中实现查看相机点的最佳方法
- pdf - PDF 文件链接问题 - 我可以链接到同一文件中的不同页面吗?
- javascript - Excel 喜欢使用 react-data-grid 和 primereact 多选进行过滤
- python - 熊猫时间转换和经过时间
- c++ - C++ 访问函数内创建的数组
- llvm - LLVM,如何获取变量名?
- javascript - 循环遍历多个值并从数组中删除
- python - 延迟后如何更改 Python-Tkinter-Canvas 中对象的颜色
- sql - 带有 FREETEXT 的 SQL 选择结果/返回出现次数较多的行
- python - 将简单的 curl 调用转换为 python/django 请求