如何使用sql server修剪字符串中大写字符之前的所有小写字符
如何编写SQL Server查询来修剪字符串中第一个大写字符之前的所有小写字符? e、 g.字符串值“eaplgCostPrice”,删除“eaplg”并将“CostPrice”传递到新列如果与某些排序规则结合使用,则它可以根据大小写运行 示例代码片段:如何使用sql server修剪字符串中大写字符之前的所有小写字符,sql,sql-server,Sql,Sql Server,如何编写SQL Server查询来修剪字符串中第一个大写字符之前的所有小写字符? e、 g.字符串值“eaplgCostPrice”,删除“eaplg”并将“CostPrice”传递到新列如果与某些排序规则结合使用,则它可以根据大小写运行 示例代码片段: -- -- using a table variable for demonstration purposes -- declare @Table table (id int identity(1,1), col varchar(30)); i
--
-- using a table variable for demonstration purposes
--
declare @Table table (id int identity(1,1), col varchar(30));
insert into @Table (col) values ('eaplgCostPrice'),('SellPrice'),('amount');
--
-- trim leading lowercases when needed
--
select col,
(case
when patindex('[a-z]%[a-z][A-Z]%', col COLLATE Latin1_General_Bin) > 0
then substring(col, patindex('%[A-Z]%', col COLLATE Latin1_General_Bin), len(col))
else col
end) as trimmedCol
from @Table
col trimmedCol
------------------ ----------------
eaplgCostPrice CostPrice
SellPrice SellPrice
amount amount
结果:
--
-- using a table variable for demonstration purposes
--
declare @Table table (id int identity(1,1), col varchar(30));
insert into @Table (col) values ('eaplgCostPrice'),('SellPrice'),('amount');
--
-- trim leading lowercases when needed
--
select col,
(case
when patindex('[a-z]%[a-z][A-Z]%', col COLLATE Latin1_General_Bin) > 0
then substring(col, patindex('%[A-Z]%', col COLLATE Latin1_General_Bin), len(col))
else col
end) as trimmedCol
from @Table
col trimmedCol
------------------ ----------------
eaplgCostPrice CostPrice
SellPrice SellPrice
amount amount
这可能会有帮助(SQL Server):是的,SQL Server。字符串值“eaplgCostPrice”,删除“eaplg”并将“CostPrice”传递给新列