Copy codeThe Code is as follows:
/*
-- Set uppercase letters for the first character string in SQLServer:
-- Author: jinjazz/csdn
-- Enable OLEAutomation in SQLServer2005
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)
*/