Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Increment the value

Author  Topic 

Anushka
Yak Posting Veteran

79 Posts

Posted - 2008-05-09 : 09:41:15
If there is one field such as Seq No in a table and if we entered some data ..
and if we update one record of Seq No then the below records of Seq No should be incremented in that table

for example there are 10 seq no's and if i had updated the seq no 4 to 5 then the
5 shuld b inc 6 and 6 to 7 etc............

at preasent i wrote only
update in sp of that particular record:
like this

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


ALTER PROCEDURE [dbo].[UpdateSelected]
(

@Description NVARCHAR(30),
@SequenceNo int
)
AS

UPDATE Sequence SET
Description = @Description,
SequenceNo = @SequenceNo

WHERE
SectionID = @SectionID
but now i need additional functionaly like inc the remaining sq no above that given no...

Regards,
Anushka

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-09 : 09:49:39
May be this:-
ALTER PROCEDURE [dbo].[UpdateSelected]
(
@SectionID int,
@Description NVARCHAR(30),
@SequenceNo int
)
AS

UPDATE Sequence SET
SequenceNo =SequenceNo +1
WHERE SequenceNo>@SequenceNo

UPDATE Sequence SET
Description = @Description,
SequenceNo = @SequenceNo
WHERE
SectionID = @SectionID
Go to Top of Page
   

- Advertisement -