Email: Password:       Forgot Password 
    .netCodeSG
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.
 
TECHNOLOGIES:
 

SQL Server - Update existing column value in serial number

Article:
Viewed:  578 
Posted On:  4/1/2016 5:59:38 PM 
Without applying loop how we can arrange column value in Serial number way in SQL Server? 

 

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.

I have below table in my SQL Server Data Base:

1.png

Image 1.

Table script:

CREATE TABLE [dbo].[Employee_Rank](
          [EmployeeName] [varchar](50) NULL,
          [Rank] [int] NULL
) ON [PRIMARY]
GO
 

Data in Table:

 

2.png

 

Image 2.

 

Now my requirement is below:

 

3.png

 

Image 3.

 

So I wrote below SQL Statement:

 

4.png

 

Image 4.

 

DECLARE @SRNO INT =0;
UPDATE EMPLOYEE_RANK SET @SRNO = RANK = @SRNO + 1
SELECT * FROM EMPLOYEE_RANK  

 

  Comment:
         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us