एक तरीका है outer apply . का उपयोग करना :
select t.*, t2.orig as newval
from @t t outer apply
(select top 1 t2.*
from @t t2
where t2.id >= t.id and t2.orig is not null
order by t2.id
) t2;
विंडो फ़ंक्शंस (SQL Server 2012+ में) के साथ ऐसा करने का एक तरीका यह है कि आईडी पर एक संचयी अधिकतम का उपयोग व्युत्क्रम क्रम में किया जाए:
select t.*, max(orig) over (partition by nextid) as newval
from (select t.*,
min(case when orig is not null then id end) over (order by id desc) as nextid
from @t
) t;
सबक्वेरी को अगले गैर-NULL . का मान मिलता है पहचान। बाहरी क्वेरी तब orig . फैलती है समान आईडी वाली सभी पंक्तियों पर मान (याद रखें, समान nextid वाली पंक्तियों के समूह में , केवल एक के पास एक गैर-NULL होगा orig . के लिए मान )।