Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Demo
CREATE TABLE Yourtable ([datekey] int, [pointkey] int, [filter_key] varchar(4), [t_key] int) ; INSERT INTO Yourtable ([datekey], [pointkey], [filter_key], [t_key]) VALUES (5506061, 37, NULL, 1), (5506061, 37, NULL, 1), (5506061, 37, NULL, 1), (5506061, 37, NULL, 1), (5506061, 37, NULL, 1), (5506061, 37, NULL, 1), (5506763, 37, NULL, 2), (5506763, 37, NULL, 2), (5506763, 37, NULL, 2), (45643, 97, NULL, 2), (45643, 97, NULL, 2), (45643, 97, NULL, 2), (45643, 97, NULL, 2), (45643, 97, NULL, 2), (45643, 97, NULL, 2), (1234, 83, NULL, 1), (1234, 83, NULL, 1), (1234, 83, NULL, 1), (1234, 83, NULL, 1), (1234, 83, NULL, 1), (1234, 83, NULL, 1) ; ;with cte as ( SELECT datekey, pointkey, filter_key, CASE WHEN t_key = 1 AND Row_number()OVER(Partition by datekey ORDER BY pointkey) = 1 THEN 1 ELSE 2 END AS new_filter_key, t_key FROM Yourtable ) update cte set filter_key = new_filter_key select * from yourtable
run
|
edit
|
history
|
help
0
sql server dynamic 12 month time series and pivot with month year column names
SQL Directives Order of Execution
updated
SQL_Joins_Intersect_Except_Union
exp8
Max from multiple columns
wall
jueves(08)
Return a single column that matches a parameter
practice sql_12AUG