Click here to Skip to main content
15,887,302 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello there
need your help for following problem if m having a master table as
<pre>
Lead_ID	Lead_Name(KM)
0	    1-8
1	    1-25
2	    1-50
3	    1-100
4	    1-150
5	    1-200
7	    1-300

and another table for distance , as
SocId      GdnID        Distance(KM)
x           Y             20
A           B             30
C           D             15
E           F             4

Now i need to get the lead id from 1st table
such as if i get the distance = 4 then lead id will be 0 as it is between 1-8 and no need to check in 1-25, 1-50, 1-100 ...so on
similar if i get the distance = 20 then lead id will be 1 as it is between 1-25 and no need to check in 1-50 ...so on
similar if i get 35 then lead id will be 2 as it is between 1-50 and no need to check in 1-100 ...so on

What I have tried:

tried with temp table eliminate after - and check with digit wheather value is low or high, but i takes a long time as i m using loop
Posted
Updated 22-Apr-19 4:06am

That's what happens when you use silly codes.

You're dealing with "ranges":
0: 1,8
1: 9,25
2: 26,50
etc.

You add those "high and low" values to your lookup table, and compare "between".
 
Share this answer
 
Don't store data as strings, unless they genuinely are and will always be treated as, strings. Name, Addresses, phone numbers - they are all strings.
"1-8", "1-25" and so forth aren't, because you want to treat them as numbers in order to find out if something is in a range.
So store them as two separate numbers!
LeadID LeadMin LeadMax
0            1       8
1            9      25
2           26      50
...
Now, your problem becomes trivial:
SQL
SELECT LeadID FROM MyTable WHERE value BETWEEN LeadMin AND LeadMax
 
Share this answer
 
Comments
Anuragintit 23-Apr-19 4:06am    
sorry for previous comment, i think it is helpful , let me try..thankss..........
OriginalGriff 23-Apr-19 4:17am    
You're welcome!
(I was just trying to work out what your comment meant!)
Anuragintit 23-Apr-19 5:35am    
Many Thanks @OriginalGriff, working fine....
OriginalGriff 23-Apr-19 5:45am    
:thumbsup:

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