Copy Code code as follows:
/*
--sqlserver capitalize the first letter of the string:
--Author: jinjazz/csdn
--sqlserver2005 Enable 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) ')
/* Output
Create Function fn_totitlecase (@Instr Varchar (8000)) Returns Varchar (8000)
*/