views:

19

answers:

1

I have a table with 3 column's in a table on a MS SQL 2008 Database

ID
ToolID
Count

Can someone toss me a script that will create a stored procedure that accepts the param ToolID and increases its value by 1?

All of my efforts have failed.

+2  A: 

try:

CREATE PROCEDURE IncrementToolCount
(
   @ToolID  int
)
AS
SET NOCOUNT ON

UPDATE Tools_Usage SET [Count]=ISNULL([Count],0)+1 WHERE ToolID=@ToolID

GO
KM
Count is what I wanted to update. And it seems to run fine, but it doesnt seem to increase the value, I think that's my LINQ thou. Table name is 'Tools_Usage'
Landmine
If Count is currently null, then this script won't work. Set a default on the Count field to 0.
Chris Lively
@Tyler, I'm not sure if LINQ will know to refresh its local value after you run this procedure. @Chris Lively, thanks, I've corrected the handling of NULL values.
KM
Thank you both! I learned something today!
Landmine