Example( jhon, bosco) in contact’s table , jhon is first and bosco is last name, how to find all contacts starts with a letter(eg:- b) in their last name,
Note. Fists name and last name in a single colum separated by comma
Answer by Magnus Ahlkvist ·
Not sure if this is homework or not.
Anyway, what you need to do is use the SUBSTRING function to look at one character following the pattern ', ' (comma and space). You will find the position of that pattern with the function CHARINDEX.
So basically WHERE SUBSTRING ( column_name, <your charindex expression>, 1 ) = 'b'
A warning though: If this is a big table, you will get bad performance. There's no way for SQL Server to search in an index for this expression, so it will mean (at least) an index scan, possibly a clustered index scan (table scan).