Skip to content
Advertisement

How do I join a sparse table and fill rows between in SQL Server

How can I apply weights from a one table to another [Port] where the weight table has sparse dates?

[Port] table

[Weights] table

So, I want to use the weights as if I had a full table like this below. i.e. change to new weight on first day it appears in [Weights] table:

Advertisement

Answer

You can use apply:

outer apply is usually pretty efficient, if you have the right indexes. In this case, the right inex is on weights(utcDT desc).

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement