Solved

Want to know the best way

Posted on 2006-11-07
4
154 Views
Last Modified: 2010-04-30
I have a table and data stored as follows

ID          MIN          MAX                    VALUE
1           0              15                              25
1           16            30                              50
1           31            45                              75
1           46           300                            100

I have a value called x

x = 35

Now I need to find out a way to find that x is basically in which slot. I'm not using SQL statesments in my code. Only storedprocudures.

please let me know the best way it.

Currently what I did was

I have a function and I'm passing the x value to it and there I'm getting those records into a recordset and in a for loop I'm checking the no is exist or not.

I need a better way of doing it
 

         
0
Comment
Question by:ananmanan
  • 3
4 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 25 total points
ID: 17895812
create function dbo.getslot ( @x int )
returns int
as
  return (select value from yourtable where @x between [MIN] and [MAX])


and you can use it like this:

select * from dbo.getslot(35)
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17895813
... assuming sql server, of course
0
 
LVL 1

Author Comment

by:ananmanan
ID: 17895878
select * from dbo.getslot(35)

What is this "getslot" Is it the table name or what. If its a sp or a view how do I write it

please explain this bit more
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 17895895
getslot is the name of the function I suggested you to create.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question