Hello everyone
I have one integer column of serial no in sql server table.
I am inserting values in it by incrementing from last one by 1
I want query such as
when i delete any one record from dot net front end then sr nos greater than that no should get decrease by one
Hope you understand
please help
Loading

Jaganathan BantheswaranPosted Jul 29, 2011, 2:27 AM
Create a stored proc which contains the below code,
-- Get the number of rows in the looping table
DECLARE @RowCount INT
SET @RowCount = (SELECT COUNT(SN) FROM @myTable where SN > @serialNumber)
-- Declare an iterator
DECLARE @I INT
-- Initialize the iterator
SET @sn = @serialNumber + 1;
SET @I = 1;
-- Loop through the rows of a table @myTable
WHILE (@I <= @RowCount)
BEGIN
UPDATE @myTable SET SN = @sn - 1 where SN = @sn
SET @sn = @sn + 1
-- Increment the iterator
SET @I = @I + 1
END
Suthish NairPosted Jul 30, 2011, 5:59 AM
Mayur GujrathiPosted Jul 29, 2011, 2:51 AM
i did it as follows