-- SQL String Functions (Samples)
--1-) LEN: It gives charater length
Select EmployeeID, LEN(LastName) as [LastNameCharacterLen], LEN(FirstName) as [FirstNameCharacterLen] from Employees
go
--2-) Concat : It merges two or more strings
Select CONCAT(FirstName , ' ' ,LastName) as [Full Name] from Employees
Select CONCAT(FirstName , SPACE(1) , LastName) as [Full Name] from Employees -- Space(1) it's a space
go
--3-) CharIndex Find out character indexs(
-- Where is the b letter? etc...
Select CHARINDEX('ber',FirstName) [{CharIndex]from Employees
Select CHARINDEX('senta',Title) as [CharIndex] from Employees
go
--4-) Lower : It gives a lower character for all strings
Select FirstName,LastName,Title,LOWER(TitleOfCourtesy) AS [TitleOfCourtesy] from Employees
go
--5-) Upper : It gives a upper character for all strings
Select FirstName,LastName,UPPER(TitleOfCourtesy) as[TitleOfCourtesy], Title from Employees
go
--6-) LTrim ve RTrim : It's remove space if you use Ltrim = clear left spaces , Rtrim clear right spaces
Declare @character varchar(30)
set @character=' from which data from SQL Server '
Select @character as[ Karakter]
Select LTRIM(@character) as[Left Trim]
Select RTRIM(@character) as[Right Trim]
go
--7-)Substring : This method extracts strings and create a new string value
Declare @city varchar(20)
set @city='Istanbul,Turkey,Canada'
Select SUBSTRING(@city,0,5)
Select SUBSTRING(@city,0,15)In this code, I explain string functions in Sql. How do we use end the write some codes here.
