Declare @StoreFrontPickingStart BIT = 0; Declare @POG as...

0

Please login or register to vote for this query.

(click on this box to dismiss)

Audio-Video Production Meta

Q&A for engineers, producers, editors, and enthusiasts spanning the fields of audio, video, and media creation

Declare @StoreFrontPickingStart BIT = 0;

Declare @POG as Table
(
	ID INT PRIMARY KEY IDENTITY(1, 1),
	Aisle INT,
	Aisle_Side Varchar(1),
	Bay INT,
	X INT,
	Y INT
)

INSERT INTO @POG
values 
(5, 'L', 1, 5, 5), (5, 'R', 1, 25, 5), 
(5, 'L', 2, 5, 10), (5, 'R', 2, 25, 10), 
(5, 'L', 3, 5, 15), (5, 'R', 3, 25, 15), 
(5, 'L', 4, 5, 20), (5, 'R', 4, 25, 20), 
(5, 'L', 5, 5, 25), (5, 'R', 5, 25, 25), 
(5, 'L', 6, 5, 30), (5, 'R', 6, 25, 30), 
(5, 'L', 7, 5, 35), (5, 'R', 7, 25, 35), 
(5, 'L', 8, 5, 40), (5, 'R', 8, 25, 40)

Select *, 
(
  CASE @StoreFrontPickingStart 
    WHEN 0 THEN DENSE_Rank() OVER (ORDER BY Y ASC)
    ELSE DENSE_Rank() OVER (ORDER BY Y DESC)
  END
) AS DenseRank,
(
  CASE @StoreFrontPickingStart 
    WHEN 0 THEN 
    (2 * (DENSE_Rank() OVER (ORDER BY Y ASC)) - 
      (
        CASE Aisle_Side WHEN 'L' THEN 1 ELSE 0 END
      )
    )
    ELSE
    (2 * (DENSE_Rank() OVER (ORDER BY Y DESC)) - 
      (
        CASE Aisle_Side WHEN 'L' THEN 1 ELSE 0 END
      )
    )
  END
) AS TranslatedBay
from @POG order by ID

Enter Parameters

Options:
Switch sites:
loading Hold tight while we fetch your results