Created
December 22, 2016 18:15
-
-
Save aramkoukia/e6b844493f59de0d9182b24be9cff124 to your computer and use it in GitHub Desktop.
Filling NULL values with Preceding Non-NULL values - Option 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- First of all I'll just put the data from my main table into a temp table | |
-- just to make sure i am not destroying the actual data if something went wrong. | |
SELECT * INTO #Temp FROM ImportedSales; | |
;With CTE As | |
( | |
SELECT ProductName , Id , COUNT(ProductName) | |
OVER(ORDER BY Id ROWS UNBOUNDED PRECEDING) As MyGroup FROM #Temp ), GetProduct AS ( | |
SELECT [ProductName] , First_Value(ProductName) | |
OVER(PARTITION BY MyGroup | |
ORDER BY Id ROWS UNBOUNDED PRECEDING | |
) As UpdatedProductName FROM CTE | |
) | |
UPDATE GetProduct | |
SET ProductName = UpdatedProductName; | |
SELECT * FROM #Temp; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment