Solved

T-SQL handling BETWEEN with two parameters

Posted on 2014-12-23
2
156 Views
Last Modified: 2014-12-23
I'm trying to use between to identify when a value falls between 2 numbers. For example
select rec from xxx where 100 between 50 and 200 This returns the rows however if I flip the numbers
select rec from xxx where 100 between 200 and 50 it fails

End User will be entering beginning and ending sequence numbers its possible that the entries will be reversed where the larger number is actually the beginning sequence number So I cant just flip the numbers to satisfy the rule.
0
Comment
Question by:bensonwalker
2 Comments
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 40515223
select rec from xxx
where 100|<column>
    between case when @value1 < @value2 THEN @value1 ELSE @value2 END
    and case when @value1 < @value2 THEN @value2 ELSE @value1 END
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

730 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