Solved

Want to know the best way

Posted on 2006-11-07
4
152 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
Comment Utility
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]
Comment Utility
... assuming sql server, of course
0
 
LVL 1

Author Comment

by:ananmanan
Comment Utility
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]
Comment Utility
getslot is the name of the function I suggested you to create.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

762 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now