YOUR AD GOES HERE

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

Published 01, Feb 2017

kudvenkat


Description:
Text Article
http://csharp-video-tutorials.blogspot.com/2017/01/sql-query-to-select-all-names-that.html

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.
https://www.youtube.com/channel/UC7sEwIXM_YfAMyonQCrGfWA/?sub_confirmation=1

Slides
http://csharp-video-tutorials.blogspot.com/2017/01/sql-query-to-select-all-names-that_31.html

SQL Server Interview Questions and Answers text articles & slides
http://csharp-video-tutorials.blogspot.com/2014/05/sql-server-interview-questions-and.html

SQL Server Interview Questions and Answers playlist
https://www.youtube.com/playlist?list=PL6n9fhu94yhXcztdLO7i6mdyaegC8CJwR

All Dot Net and SQL Server Tutorials in English
https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd

All Dot Net and SQL Server Tutorials in Arabic
https://www.youtube.com/c/KudvenkatArabic/playlists

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'

Releted More Videos

You May Also Like

YOUR AD GOES HERE

YOUR AD GOES HERE