|
-
Nov 23rd, 2021, 07:39 AM
#1
Thread Starter
Member
[RESOLVED] Trickish Situation With Data Range Search
Hello,
Please i need help with the following situations.
I have a database table named "tabJrecord" which contains ranges of numbers, like as shown below :
| Col1 |
Col2 |
Col3 |
Col4 |
| Apple |
REF1 |
6000 |
6400 |
| Banana |
REF2 |
6500 |
6800 |
| Orange |
REF3 |
7000 |
8000 |
Now, i have a form which accepts a number, i want to be able to search if that number exist in any range of any row in the table.
For example, if a user enters number 6,300. I want to be able search the table rows and my recordset should be able to tell me the number 6,300 exist in for the Fruit "Banana". That is if the number is between Col3 and Col4 of any row.
Kindly help with the MSSQL Query for this.
Thanks.
Last edited by Tobyy; Nov 23rd, 2021 at 07:43 AM.
-
Nov 23rd, 2021, 07:49 AM
#2
Re: Trickish Situation With Data Range Search
Code:
select Col1, Col2 from tabJrecord where Col3 >= 6300 and Col4 <= 6300 and Col1 = 'Banana'
But given the data, there is no record Banana which matches 6300.
-
Nov 23rd, 2021, 08:31 AM
#3
Re: Trickish Situation With Data Range Search
Code:
SELECT * FROM tabjrecord WHERE 6300 BETWEEN Col3 AND Col4
And i agree with Arnout: No Banana, but Apple instead
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Nov 23rd, 2021, 08:43 AM
#4
Fanatic Member
Re: Trickish Situation With Data Range Search
Why SQL ?
With DAO, just do a Inner Loop using a Seek which searches each column other than 1.
Once found read column1 value for your answer.
I agree with the other posted, in the example given the result set would be Not Found!
-
Nov 23rd, 2021, 08:55 AM
#5
Re: Trickish Situation With Data Range Search
 Originally Posted by vb6forever
Why SQL ?
Because it's a Database.
And filtering your resultset on the Server-side via SQL will always beat a seek on a complete table.
EDIT: IIRC, seek only works on a single Comparator. In OP's case he has to compare the value to two Columns simultainiously with different operators
Meaning you have to do the operation twice.
Nevermind with Seek you only get one result back (the first one found). If you want all, you would have to "continue" seeking.
And seek is only "fast" on Indexed search-keys. If you search on non-indexed columns it's a sequential iteration through the table
Last edited by Zvoni; Nov 23rd, 2021 at 09:09 AM.
Last edited by Zvoni; Tomorrow at 31:69 PM.
----------------------------------------------------------------------------------------
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------------------
People call me crazy because i'm jumping out of perfectly fine airplanes.
---------------------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad
-
Nov 23rd, 2021, 09:36 AM
#6
Re: Trickish Situation With Data Range Search
 Originally Posted by Zvoni
EDIT: IIRC, seek only works on a single Comparator. In OP's case he has to compare the value to two Columns simultainiously with different operators
Meaning you have to do the operation twice.
Nevermind with Seek you only get one result back (the first one found). If you want all, you would have to "continue" seeking.
And seek is only "fast" on Indexed search-keys. If you search on non-indexed columns it's a sequential iteration through the table
Seek method works only in JET and only when there is an index on the column being searched.
This is the way DBF files are used, very educational if you are used to SQL with whatever predicate you wish in the WHERE clause. Makes you think more about indexing and those abysmal tables scans.
Alas no, you cannot use Seek with MSSQL no matter if there is an index on the column or not. It's just not supported by the OLEDB provider (or any other access driver/provider) AFAIK.
cheers,
</wqw>
-
Dec 18th, 2021, 09:48 PM
#7
Thread Starter
Member
Re: Trickish Situation With Data Range Search
 Originally Posted by Zvoni
Code:
SELECT * FROM tabjrecord WHERE 6300 BETWEEN Col3 AND Col4
And i agree with Arnout: No Banana, but Apple instead
Thank you soooooooooooooooooooooooooooo much.
This worked PERFECTLY !
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|