sql-server - 将正确的函数应用于列中的子字符串
问题描述
我们的 SQL Server 2014 系统有一个propercase函数,效果很好。我正在尝试将其应用于包含出生城市、州和国家/地区组合的列的子字符串。
例如
birthplace
LOS ANGELES, CA US
DALLAS, TX US
GRAND RAPIDS, MI US
希望它是
birthplace
Los Angeles, CA US
Dallas, TX US
Grand Rapids, MI US
如果我应用它当前显示的propercase函数
birthplace
Los Angeles, Ca Us
Dallas, Tx Us
Grand Rapids, Mi Us
任何帮助,将不胜感激。
解决方案
好 。. . 假设所有出生地都有一个逗号,并且您希望propercase()
最多到第一个逗号:
select (dbo.propercase(left(birthplace, charindex(',', birthplace))) +
substring(birthplace, charindex(',', birthplace) + 1)
)
我会注意到这种方法不能修复拼写错误,因此它不会将“Grand Rapids”更改为“Grand Rapids”。;)
推荐阅读
- android - 指定为非空的改造参数为空
- python - 如何删除 NumPy 数组中的数字?
- java - 如何改变约束偏差?
- sass - sass parent name shortcut need better way
- .net - 将文件存储在我们的数据库中与将它们存储在文件服务器上。如果我想对可以查看文件的人应用自定义权限
- javascript - JavaScript 清除数组值
- matlab - 链接和排序两个数组
- python-3.x - Get end date of months that lie between two given dates in a pandas dataframe
- html - Overlapping middle contents with header and footer divs
- linux - http 重定向一个 azure Web 应用程序