sqlsql-servert-sqluppercaselowercase

Change the casing of my letters in string using sql function


I want to convert my string into opposite casing in sql using function. can someone help me??

I am able to do the first letter of the string but not middle letters

http://www.sql-server-helper.com/functions/initcap.aspx

Example:

input: "hI mY Name IS Joe"

output: "Hi My nAME is jOE"


Solution

  • If your sql-server version support (sql-server-2017 and above), you can use TRANSLATE function

    SELECT TRANSLATE ('hI mY Name IS Joe' COLLATE Latin1_general_CS_AS 
        ,'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
        ,'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') 
    

    Result:

     Hi My nAME is jOE