Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to display only the name of employees that starts only with
"San".But when i am using the "Like" statement in sql i shows ,all the names that is having the letters "San" continuously.



My code is as follows...


select * from tabName where empName like "San%"


please help Me to get the names that only starts with "San"



Eg. Output is
the table contains the following EmpName

1.santhanam
2.Santhose
3.Magesan

If i use the above query,It will display all the names.But I want to get only the names That are starts with "San".I need the following names,

1.santhanam
2.Santhose



Thanks in advance friends.........
Posted
Comments
__TR__ 21-Nov-12 1:21am    
Your query seems to be working correctly when I tried it.

CREATE TABLE #SampleTable
(
ID INT,
EmpName VARCHAR(100)
)

INSERT INTO #SampleTable
SELECT 1, 'santhanam' UNION ALL
SELECT 2, 'Santhose' UNION ALL
SELECT 3, 'Magesan'

select * from #SampleTable where empName like 'San%'

DROP TABLE #SampleTable
Rohini Palanichamy 21-Nov-12 1:53am    
What i need is i want to get only the names that starts with "San"
__TR__ 21-Nov-12 2:36am    
Try
select * from tabName where empName like 'San %'

you can use your query something like below if number of starting characters are fix :

SQL
select * from tabName where left(EmpName,3) = 'San'
 
Share this answer
 
Comments
Rohini Palanichamy 21-Nov-12 3:43am    
It is also working fine Mr.Bhushan.
SQL
select * from tablename where empName like 'san_%'
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900