October 12, 2009 at 8:25 am
Hi
i want to write a store procedure for adding 1 to a field
i wrote this
but it does not work
ALTER PROCEDURE [dbo].[DownloadCount_SP]
AS
BEGIN
select * from DownloadInfo
update [DownloadCount] set [DownloadCount+1]
END
go
regards
Nazanin
October 12, 2009 at 8:37 am
Not sure why you want a stored proc for something like this but here goes
What TABLE are you trying to uypdate - you select from one name, and then try to update a different one.
There is no need to select from the table prior to the update
Your update statement should be something like:
Update TABLENAME
Set COLUMNNAME = COLUMNNAME + 1
And I suspect ypu want a where clause otherwise you wiull add 1 to the column in every row.
If you canpost more details of what you atrying to do along with the DDL that describes the tables I am sure you will get more help.
Mike John
October 12, 2009 at 8:42 am
As Mike showed, you need to write the update statement first.
Once you do that, just enclose it in a stored procedure.
create procedure UpdateDownload
as
update....
return
Let me say that I might recommend you make this paramaterized, in case you need to change the update. Maybe you only want to update one item.
create procedure UpdateDownload
@ItemID int
as
update....
set x = x + 1
where ItemID = @ItemID
return
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply