Sql query to select all names that start with a given letter without like operator

Описание к видео Sql query to select all names that start with a given letter without like operator

Text Article
http://csharp-video-tutorials.blogspo...

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.
   / @aarvikitchen5572  

Slides
http://csharp-video-tutorials.blogspo...

SQL Server Interview Questions and Answers text articles & slides
http://csharp-video-tutorials.blogspo...

SQL Server Interview Questions and Answers playlist
   • SQL Server Interview Questions and An...  

All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenka...

All Dot Net and SQL Server Tutorials in Arabic
   / kudvenkatarabic  

In this video we will discuss writing a SQL query to retrieve all student names that start with letter 'M' without using the LIKE operator.

If the interviewer has not mentioned not to use LIKE operator, we would have written the query using the LIKE operator as shown below.
SELECT * FROM Students WHERE Name LIKE 'M%'

We can use any one of the following 3 SQL Server functions, to achieve exactly the same thing.
CHARINDEX
LEFT
SUBSTRING

The following 3 queries retrieve all student rows whose Name starts with letter 'M'. Notice none of the queries are using the LIKE operator.
SELECT * FROM Students WHERE CHARINDEX('M',Name) = 1
SELECT * FROM Students WHERE LEFT(Name, 1) = 'M'
SELECT * FROM Students WHERE SUBSTRING(Name, 1, 1) = 'M'

Комментарии

Информация по комментариям в разработке