Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 search for a number between 2 numbers in row

Author  Topic 

Warsha
Starting Member

4 Posts

Posted - 2013-09-19 : 09:14:08
Hi all,

I have a case where a need to search for a givin number, and that number should be between a begin and end number stored in a row in atble. see the table below.

descr begin end qty
apple 1 200 200
bags 1 400 400
mangos 1 100 100
apple 201 700 500

if I search for apple number 17 then the query should bring me to

apple 1 200 200

Is it posssile?

I really hope someone can help me

Regards,

Warsha

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2013-09-19 : 09:18:54
select * from table where [descr] = 'apple' and 17 between [begin] and [end]


Too old to Rock'n'Roll too young to die.
Go to Top of Page

Warsha
Starting Member

4 Posts

Posted - 2013-09-19 : 11:03:58
Thanks! That worked....

regards,

Warsha
Go to Top of Page

sigmas
Posting Yak Master

172 Posts

Posted - 2013-09-19 : 11:20:30
select * from table where [descr] = 'apple'
and 17 >= [begin] and 17 <= [end]
Go to Top of Page
   

- Advertisement -