SQL syntax to increment field value by 1?

  • Thread starter Thread starter VB Programmer
  • Start date Start date
V

VB Programmer

What is the SQL Express SQL syntax to increment a field by 1?

The stored proc doesn't like this:

CREATE PROCEDURE dbo.VideoViewIncrement
@VideoId nchar(40),
AS
UPDATE Videos SET TimesViewed = TimesViewed + 1 WHERE (VideoId = @VideoId)
RETURN

Any ideas?

Thanks.
 
VB said:
What is the SQL Express SQL syntax to increment a field by 1?

The stored proc doesn't like this:

CREATE PROCEDURE dbo.VideoViewIncrement
@VideoId nchar(40),
AS
UPDATE Videos SET TimesViewed = TimesViewed + 1 WHERE (VideoId = @VideoId)
RETURN

The following works for me on SQL Server 2000

UPDATE Videos SET TimesViewer = ((SELECT TimesViewed FROM Videos WHERE VideoId = @VideoId) + 1) WHERE VideoId = @VideoId
 
Please please please always tells us what is the exact result (error message
?) you get instead of just saying us it "doesn't like"...

For now I see an extra comma after the parameter declaration ? Is this in
your code ?

Do you have an "Incorrect syntax near the keyword 'AS'." message ?
 
Thanks Patrice. You are correct....

Patrice said:
Please please please always tells us what is the exact result (error
message
?) you get instead of just saying us it "doesn't like"...

For now I see an extra comma after the parameter declaration ? Is this in
your code ?

Do you have an "Incorrect syntax near the keyword 'AS'." message ?
 
UPDATE Videos SET TimesViewed = TimesViewed + 1 WHERE (VideoId = @VideoId)
is simpler and correct...

For now I suspect an extra comma before the AS keyword to cause a syntax
error message...

--
Patrice

Sericinus hunter said:
The following works for me on SQL Server 2000

UPDATE Videos SET TimesViewer = ((SELECT TimesViewed FROM Videos WHERE
VideoId = @VideoId) + 1) WHERE VideoId = @VideoId
 
Back
Top