I have a box of size width x height x length. The dimensions must not exceed the maximum dimensions. Currently I'm sorting the box dimensions from smallest to largest and the maximum dimensions too. Then I compare pairwise the 3 values like below (pseudo C# code).
Is there are faster way to do this in a stored procedure in SQL Server?
var maximumDimensions = [ maxLength, maxHeight, maxWidth ];
lockerDimensions.Sort();
var parcelDimensions = [ itemLength, itemHeight, itemWidth ];
parcelDimensions.Sort();
for (var i = 0; i < 3; i++)
{
if (parcelDimensions[i] > lockerDimensions[i])
{
return false; //parcel size invalid because maximum dimension exceeded
}
}
return true; //ok parcel size is valid
In SQL I have 6 conditions. Is there something simpler?
DECLARE @dimensionsValid bit = (SELECT CASE WHEN
(
(@length <= @MaxLength AND @width <= @MaxWidth AND @height <= @MaxHeight)
OR (@width <= @MaxLength AND @length <= @MaxWidth AND @height <= @MaxHeight)
OR (@height <= @MaxLength AND @length <= @MaxWidth AND @width <= @MaxHeight)
OR (@length <= @MaxLength AND @height <= @MaxWidth AND @width <= @MaxHeight)
OR (@width <= @MaxLength AND @height <= @MaxWidth AND @length <= @MaxHeight)
OR (@height <= @MaxLength AND @width <= @MaxWidth AND @length <= @MaxHeight)
)
THEN 1 ELSE 0 END)