SQL Server: Update Existing Column Value in Serial Number

回覆文章
yehlu
Site Admin
文章: 3245
註冊時間: 2004-04-15 17:20:21
來自: CodeCharge Support Engineer

SQL Server: Update Existing Column Value in Serial Number

文章 yehlu »

https://www.c-sharpcorner.com/blogs/sql ... ial-number

In this article I am going to show how we can update our existing column value with serial number without using loop. Below is my problem.

facebook
twitter
linkedIn
Reddit
expand
Download Free .NET & JAVA Files API
I have the below table in my SQL Server Data Base:

database

Table script:
CREATETABLE [dbo].[Employee_Rank](
[EmployeeName] [varchar](50)NULL,
[Rank] [int] NULL
)ON [PRIMARY]

GO
Data in Table:

table

Now my requirement is below:

requirement

So I wrote the below SQL Statement:

Statement
DECLARE @SRNO INT=0;
UPDATE EMPLOYEE_RANK SET @SRNO =RANK= @SRNO + 1

SELECT*FROM EMPLOYEE_RANK
回覆文章

回到「SQL Server」