Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Solution to finding record right before and after a valu
Message
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00697292
Message ID:
00699518
Views:
18
Sergey,

I will add it once I figure out how. <s>

Regards,

Jim Smith
>Did you consider adding it to the FAQ section?
>
>>All,
>>
>>I was reading SQL Magazine and an article by Brian Moran solved a problem I had. The problem was "How do I get the record right before and right after some seed value?"
>>
>>His solution was a creative use of the MIN and MAX functions of SQL. I paraphrase his TSQL code into VFP:
>>
>>This is the code:
>>
>>SELECT * from wotype WHERE wotype.wotype_id = "0000000009" OR wotype_id IN(SELECT MAX(wotype_id) FROM wotype WHERE wotype_id < "0000000008") OR wotype_id IN(SELECT MIN(wotype_id) FROM wotype WHERE wotype_id > "0000000008")
>>
>>
>>SELECT * from wotype WHERE wotype.wotype_id = "0000000009" && seed value ; OR wotype_id IN(SELECT MAX(wotype_id) FROM wotype WHERE wotype_id < "0000000008") && Gets the max value of the subset of values that are less than the seed value.
>>OR wotype_id IN(SELECT MIN(wotype_id) FROM wotype WHERE wotype_id > "0000000008") &Gets the min value of subset of values that are greater than the seed value.
>>
>>Works as advertised. This solution gets me the value right before and right after my seed value of "0000000009".
>>
>>
>>Great work Brian!
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform