Click here to Skip to main content
12,240,822 members (71,155 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL
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 20-Nov-12 20:02pm
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 %'
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

select * from tabName where left(EmpName,3) = 'San'
  Permalink  
Comments
Rohini Palanichamy 21-Nov-12 3:43am
   
It is also working fine Mr.Bhushan.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

select * from tablename where empName like 'san_%'
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100