Skip to content

Instantly share code, notes, and snippets.

@briangithex
Created June 4, 2025 18:28
Show Gist options
  • Select an option

  • Save briangithex/dcda51bec4ccd54244eefa6fc7c20679 to your computer and use it in GitHub Desktop.

Select an option

Save briangithex/dcda51bec4ccd54244eefa6fc7c20679 to your computer and use it in GitHub Desktop.
declare @Result Table(StationName VarChar(50))
declare @Position VarChar(50) = 'A'
while(@Position is not null)
BEGIN
insert into @Result values(@Position)
declare @Override varchar(50) = (select top 1 StationToName from StationRoutingOverride where StationFromName = @position)
declare @Failover varchar(50) =
(select top 1 S2.StationName from Stations S1
join Stations S2 on S2.StationPhysicalOrder = S1.StationPhysicalOrder+1
where S1.StationName = @Position)
set @Position = coalesce(@Override,@Failover)
END
select * from @Result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment