Split One Column to 2 column - SQL Query

Split One Column to 2 column from comma separator using SUBSTRING, LEFT, LEN Functions


Select

[CorpGroupName],

[Div],

[Corps],

left([Corps], charindex(',', [Corps])-1) as City,

SUBSTRING([Corps], CHARINDEX(',', [Corps]) + 1, LEN([Corps])) as [State]

From [dbo].[Corp]



In Built Function in T-SQL - Reverse

Reverse - Returns the reverse of a character expression.
REVERSE( character_expression )


For Eg.


Select CompanyName,


Reverse(CompanyName) As ReverseName,


Reverse(Left(CompanyName,5)) As ReverseFirst5Char,


Reverse (Right (CompanyName,5)) As ReverseLast5Char


From Customers



Result




In Built Funtion in T-SQL - Left and Right

Left - Returns the left part of a character string with the specified number of characters.
LEFT( character_expression , integer_expression )

Right - Returns the Right part of a character string with the specified number of characters.
RIGHT( character_expression , integer_expression )



For Eg.

Select  CompanyName,

Left(CompanyName,5) As [Left],

Right(CompanyName,5) As [Right]

From Customers


Result






In Built Function in T-SQL - Upper and Lower

Upper - Returns a character expression with lowercase character data converted to uppercase.
Lower  -   Returns a character expression after converting uppercase character data to lowercase


For Eg.


Select CompanyName,
Lower(CompanyName) As LoweCase,
Upper(CompanyName) As UpperCase,




From Customers


Result