Click here to Skip to main content
Rate this: bad
good
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__ at 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 at 21-Nov-12 1:53am
   
What i need is i want to get only the names that starts with "San"
__TR__ at 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 at 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
0 OriginalGriff 7,105
1 DamithSL 5,079
2 Maciej Los 4,866
3 Sergey Alexandrovich Kryukov 4,617
4 Kornfeld Eliyahu Peter 4,384


Advertise | Privacy | Mobile
Web01 | 2.8.141223.1 | Last Updated 21 Nov 2012
Copyright © CodeProject, 1999-2014
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