Converting PascalCase string to quot;Friendly Namequot; in TSQL(将 PascalCase 字符串转换为“友好名称在 TSQL 中)
问题描述
我有一个表,其中一列的值来自枚举.我需要创建一个 TSQL 函数,以便在检索时将这些值转换为友好名称".
I have a table with a column whose values come from an Enumeration. I need to create a TSQL function to convert these values to "Friendly Names" upon retrieval.
示例:
'DateOfBirth' --> 'Date Of Birth'
'PrincipalStreetAddress' --> 'Principal Street Address'
我需要一个直接的 TSQL UDF 解决方案.我没有安装扩展存储过程或 CLR 代码的选项.
I need a straight TSQL UDF solution. I don't have the option of installing Extended Store Procedures or CLR code.
推荐答案
/*
Try this. It's a first hack - still has problem of adding extra space
at start if first char is in upper case.
*/
create function udf_FriendlyName(@PascalName varchar(max))
returns varchar(max)
as
begin
declare @char char(1)
set @char = 'A'
-- Loop through the letters A - Z, replace them with a space and the letter
while ascii(@char) <= ascii('Z')
begin
set @PascalName = replace(@PascalName, @char collate Latin1_General_CS_AS, ' ' + @char)
set @char = char(ascii(@char) + 1)
end
return LTRIM(@PascalName) --remove extra space at the beginning
end
这篇关于将 PascalCase 字符串转换为“友好名称"在 TSQL 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将 PascalCase 字符串转换为“友好名称"在 TSQ
基础教程推荐
- 从字符串 TSQL 中获取数字 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
