Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

can anybody tell me what is the query use for condition like
i want to select value between two value but do not want to show
those value which are use in query.
what ever query i am using in sql 2005 that are showing result
including between criteria value ex.
suppose my database have name
shiv
syam
ram
arjun
ratan
monu
then query is
select * from student where name between 'monu' and 'syam'
o/p is
monu
ratan
shiv
syam
but i want output shold be only
ratan
shiv
Thanks
Posted

Just add a not in where condition in the query (for these two names).

select * from student where name between 'monu' and 'shyam' and name not in ('monu', 'shyam')
 
Share this answer
 
Comments
call to .net 6-Dec-10 1:32am    
thanks
Abhinav S 6-Dec-10 1:34am    
You are welcome - If this answer helps, you can always mark it as answered :).
call to .net 6-Dec-10 8:13am    
ok buddy :)
select * from (select * from student order by asc) where name between 'monu' and 'shyam'
 
Share this answer
 
Comments
call to .net 6-Dec-10 1:35am    
thanks
but query is not working
arindamrudra 6-Dec-10 2:15am    
Thanks for you effort but, it is not correct in this context. The first one is best. Read the question carefully till the last. The syntax is wrong. You need to use alias. Like:
select * from (select * from student order by asc) AS Your_Alias
fjdiewornncalwe 6-Dec-10 9:33am    
Hey Sandi... Close, but you don't need to do the order by asc part in this query to achieve what you and the OP want. The between clause will cause the server to automatically do a sort by asc search. I like that you thought of the ordering as being important here, though. A good try.

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