I feel like this should be easy but I'm having the hardest time. I'm using SQL server. I'm trying to get the output from the following query to be used in an update statement to add to my table:
SELECT cons_id, credited_date,
ROW_NUMBER() OVER (partition by cons_id order by cons_id) AS Row_Counter
FROM fy23_jul_aug_anniv_jv;
My primary key is cons_id. The output looks like this:
I want the row_counter column to be a permanent column in my table called COUNTER (which I already added to my table...I just need to update it). I've tried this but I get an error saying
SQL command not properly ended.
UPDATE fy23_jul_aug_anniv_jv
SET counter = b.row_counter
FROM (SELECT cons_id, ROW_NUMBER() OVER (partition by cons_id order by cons_id) AS Row_Counter
FROM fy23_jul_aug_anniv_jv) AS b
WHERE b.cons_id = cons_id;