Live Webinar: Prompt Engineering: Skill Everyone Must Learn Today
x
C# Corner
Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Refer
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
SQL String Functions
WhatsApp
Burak Seyhan
Feb 03
2015
1.4
k
0
0
-- 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)
SQL
Strings
Functions
Up Next
SQL String Functions