seems to work fine Clarification on SQL query syntax : we have an Employee table which has two columns Emp Id and EmpName and its values looks like this:
WITH cteRowNums AS (
ROW_NUMBER() OVER(ORDER BY EmpId) AS RowNum
SET EmpName = CASE WHEN RowNum % 3 = 1 THEN 'Joe'
WHEN RowNum % 3 = 2 THEN 'John'
WHEN RowNum % 3 = 0 THEN 'Sam'
will help you I would suggest using a gem like Best in Place to allow for in-place editing on certain fields in the list. If you don't want in-place editing then utilize a modal view that contains the edit form.
Need T-SQL update statement to dynamically assign a record number
I hope this helps you . First, you want to assign a value for RecNum for all PK using ROW_NUMBER. After that, you want to update the remaining rows with the appropriate RecNum SQL Fiddle
WITH CtePKs AS(
RN = ROW_NUMBER() OVER(ORDER BY ID)
WHERE RIGHT(Name, 3) = '_pk'
UPDATE CtePKs SET RecNum = RN
SET RecNum = x.RecNum
FROM z2 z
SELECT TOP 1 Id, RecNum
ID < z.ID
AND RecNum IS NOT NULL
ORDER BY ID DESC
WHERE z.RecNum IS NULL