SQL Server sets uppercase letters

Source: Internet
Author: User

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)
*/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.