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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Increment Column Value

Author  Topic 

darenkov
Yak Posting Veteran

90 Posts

Posted - 2007-11-18 : 06:50:50
I am having trouble incrementing a column value. The code seems basic but doesn't work.


ALTER PROCEDURE [dbo].[prc_UpdateVotes]
@OptionID int
AS
BEGIN

SET NOCOUNT ON;

DECLARE @NumberOfVotes int
SET @NumberOfVotes = (SELECT Votes FROM PollOptions WHERE OptionID = @OptionID)

UPDATE PollOptions
SET Votes = (@NumberOfVotes + 1)
WHERE OptionID = @OptionID

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-11-18 : 07:18:03
[code]UPDATE PollOptions
SET Votes = (isnull(@NumberOfVotes, 0) + 1)
WHERE OptionID = @OptionID[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

darenkov
Yak Posting Veteran

90 Posts

Posted - 2007-11-18 : 07:44:06
thanks
Go to Top of Page
   

- Advertisement -