SQLServer 设置单词首字母大写

前端之家收集整理的这篇文章主要介绍了SQLServer 设置单词首字母大写前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

<div class="codetitle"><a style="CURSOR: pointer" data="20147" class="copybut" id="copybut20147" onclick="doCopy('code20147')"> 代码如下:

<div class="codebody" id="code20147">
/
--sqlServer中将字符串首字母设置大写:
--作者:jinjazz /csdn
--sqlServer2005启用OLEAutomation
sp_configure 'show advanced options',1;
go
RECONFIGURE;
go
sp_configure 'Ole Automation Procedures',1;
go
RECONFIGURE;
go
/
use tempdb
go
if (object_id ('fn_toTitleCase' ) is not null )
drop function dbo . fn_toTitleCase
go
create function fn_toTitleCase (@inStr varchar (8000 ))
returns varchar (8000 )
as
begin
declare @str varchar (8000 )
set @str = 'var data = "' +@inStr + '";
var reg = /\b(\w)|\s(\w)/g ;
data = data.toLowerCase();
data.replace(reg,function(m){return m.toUpperCase()});'
declare @object int
declare @r varchar (800 )
exec sp_OACreate 'MSScriptControl.ScriptControl',@object output
exec sp_OASetProperty @object,'Language','javascript'
exec sp_OAMethod @object,'eval',@r out,@str
return @r
end
go
select dbo. fn_toTitleCase ('create function fn_toTitleCase(@inStr varchar(8000)) returns varchar(8000)' )
/输出
Create Function Fn_totitlecase(@Instr Varchar(8000)) Returns Varchar(8000)
/

猜你在找的MsSQL相关文章