Course Content
SQL SERVER
About Lesson

/*
String Functions
*/
select ASCII(‘A’),CHAR(65);

/*Print all ascii with their code*/
declare @i int;
declare @ch varchar(2);
set @i=1;
while(@i<=255)
begin
set @ch=CHAR(@i);
–print @ch + ‘=’ + @i +’,’;
select @ch [Char],’=’,@i [Code];
set @i=@i+1;
end;

–Lower and Upper function
select ENO,Upper(FName) FirstName, Lower(Job) Job from tblemp;
select * from tblemp where lower(fname)=’scott’; — if euqalto operator sense the case
–LTRIM – Removes blanks on the left side of the given character expression.
select LTRIM(‘ Ram is good boy’);
–RTRIM – Removes blanks on the right side of the given character expression.
select RTRIM(‘Ram is good boy ‘);
–REVERSE: Reverses all the characters in the given string expression.
select REVERSE(‘Ram is good boy’);
–LEN: Returns the count of total characters,
select LEN(‘Ram is good boy’);
–LEFT Returns the specified number of characters from the left side of the given string
— Syntax: LEFT(string, number_of_characters)
select LEFT(‘Ram is good boy’,3);
–RIGHT Returns the specified number of characters from the right side of the given string
— Syntax: RIGHT(string, number_of_characters)
select RIGHT(‘Ram is good boy’,3);
–CHARINDEX:Returns the starting position of the word which you want to find in a string. –syntax CHARINDEX(‘word_to_find’,’string’,postion) –position optional
select CHARINDEX(‘good’,’Ram is good boy’);
–SUBSTRING – this function returns part of the string according to given position
— syntax: substring(‘string’,start_pos,num_of_chars);
select SUBSTRING(‘Ram is good boy’,8,4);
select eno,fname,email,SUBSTRING(email,CHARINDEX(‘@’,email)+1,len(email)-charindex(‘@’,email)) from tblemp;
— scott@yahoo.com — @ 6th , Len=15, len(email)-charindex(‘@’,email)=9
–rediff.com