Solved

T-SQL handling BETWEEN with two parameters

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS SQL Inner Join - Multiple Join Parameters 2 31
SQL Server Question 5 36
sql server select date from a datetime column 10 23
Webservices in T-SQL 3 30
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

775 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