Solved

T-SQL handling BETWEEN with two parameters

Posted on 2014-12-23
2
153 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

861 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

30 Experts available now in Live!

Get 1:1 Help Now