Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
I have a table tbltest and 3 column(id,subject,status).While implementing search using the "IN"
keyword in sql as follows:-

SQL
select * from tbltest where Rtrim(Ltrim(Subject)) in ('Call')
then it shows nothing and i have a value 'Call' in column Subject

but when i use

SQL
select * from tbltest where Rtrim(Ltrim(Status)) in ('Completed')
then it works fine.
I had tried to remove the leading and trailing spaces using rtrim and ltrim but wasn't successfull.What could be the problem in it.
Posted
Updated 10-Jan-14 4:28am
v2

SQL
select * from tbltest where Rtrim(Ltrim(Subject)) in ('Call')

select * from tbltest where Rtrim(Ltrim(Status)) in ('Completed')


In the fist statement you have use Subject column but in second statement you have used Status.
Was it intentional?
 
Share this answer
 
Comments
Sumit Bhargav 10-Jan-14 8:43am    
yes,please read the question carefully
Deviprasad Das 10-Jan-14 8:47am    
Try using

select * from tbltest where replace(Subject, ' ', '') in ('Call')
Sumit Bhargav 10-Jan-14 8:49am    
hi deviprasad,
that dosen't work either!
Deviprasad Das 10-Jan-14 9:09am    
Check this
http://www.sqlfiddle.com/#!2/dd4919/4
Karthik_Mahalingam 11-Jan-14 7:24am    
5,
your solution is correct only..
It was a data issue...
SQL
select * from tbltest where Rtrim(Ltrim(Subject)) in ('Call')


in the above query you are using the column Subject whereas in the below you are using the column Status

SQL
select * from tbltest where Rtrim(Ltrim(Status)) in ('Completed') 


Please make sure your column names are correct ??
 
Share this answer
 
Comments
Sumit Bhargav 10-Jan-14 8:46am    
hi karthik,
the second query is an example to explain which is executing successfully.
so why isn't the first query running successfully?
Karthik_Mahalingam 10-Jan-14 8:51am    
:) OMG, sorry i misunderstood.
Karthik_Mahalingam 10-Jan-14 8:51am    
did u tried with Mike Meinz 's solution ??
Sumit Bhargav 10-Jan-14 8:54am    
i can't use mike menz's solution coz it's dynamically binded and many other values can come more
Karthik_Mahalingam 10-Jan-14 8:58am    
can u pls post the subject column values..

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