Hey guys welcome back to this SQL tutorial course. In this session we will
look at some string functions. So first we have the L trim function which helps
in removing the blanks spaces on the left side of the character expression. So
let's implement this function in SQL Server. So let me first create a string
with some blank spaces on the left side while type select and then I will give
some blank spaces on the left side now let me pass in a string and I'll name
the string to be sparta I'll hit execute right so this is the
string which has some leading spaces on the left side if I want to remove all of
these blank spaces on the left side all I need to do is use the L trim function
so I will type select L trim and inside this I will pass in the string with the
leading spaces so I will copy this and I will paste it over here now let me
execute both of this simultaneously right so this is the string with the
leading spaces and when we use the L trim function all of those blank spaces
on the left side will remove then we have the lower function which basically
converts all the characters of the lower case so let's look at an example this
time let me actually print the string which has all the characters in
capitals so this is sparta so here we see that
all of the characters in the string are in capitals I'll execute this and this
is what we get. Now if I want to convert all of the characters into lowercase I
can just use a lower function so I will type select lower and then pass in the
string inside the function I will copy the string I will paste it inside this I
will hit execute so this is the string where all the characters were in
capitals and after using the lower function this string where all the
characters were in capitals have been turned to lowercase
similarly we have the upper function which basically converts all the
characters to uppercase so this time I will take in a string which has all the
characters in lowercase so select I will type hello world, let me print this
right so here we see that initially all of the characters are in lowercase
now after this I will type select upper and then pass in the string inside the
function I will copy this I will paste it over here
I will hit execute so this was our initial string and after using the upper
function we have converted the string into capital case. After that we have the
reverse function which basically reverses all the characters in the
string. So let's implement this too so let me take in a random string again
select and I will type I love ice cream I'll hit execute so this is what we get
initially now after this I will use the reverse function select reverse and I
will pass in the string inside the reverse function. I'll copy it and I will
paste it inside this function over here. Now let me execute so this is the
initial string and after using the reverse function we have reversed all of
the characters in the string right so you see that this is the starting and
this is the ending over here and after reversing it we get this final string
and finally we have the substring function which gives us a substring or
bar of the string from the original string. Now let me give in the original
string first so I will type select and then the string would be this is sparta
now let's say I would want the substring sparts from this entire string
so this is where we can use the substring function
so I will type select substring now the substring function takes in three
parameters, first is the original string so I will copy the original string and I
will pass it into this as the first parameter now after that I need to give
in the index value from where the substring starts so this is the first
character of the substring which I want so the index value would be 1 2 3 4 5 6
7 8 and 9 so I'll type 9 over here and then the third parameter would be the
length of the substring so the length of the substring is 1 2 3 4 5 and 6 so I
will pass in 6 over here. Now let me execute all of this and let's see what we
get. So this is the original string this is para and after using the substring
function we have extracted only this part from the entire string so these
were some of the string functions in SQL. Thanks for attending this session. Let's
meet in the next class