Click here to Skip to main content
15,891,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
SQL
create procedure update_sam1(@control_id as varchar) as
begin
update Table_2 set Current_Value=10 where Control_Id=1

end



hi im just trying to update a "Current_Value" in the table using stored procedure but the table is not getting updated... im new to stored procedure... please help...
Posted
Comments
Ganesan Senthilvel 23-May-12 11:14am    
Run SQL Profiler tool to debug the DB operations

Put select statement before and after update query, to validate the result

SQL
create procedure update_sam1(@control_id as varchar) as
begin
select Current_Value, Control_Id from Table_2 where Control_Id=1
update Table_2 set Current_Value=10 where Control_Id=1
select Current_Value, Control_Id from Table_2 where Control_Id=1
end
 
Share this answer
 
Comments
Member 8711310 23-May-12 11:32am    
thanks for the reply... problem still remains... DB not updating...
I suppose Current_value and Control_Id fields are numerics (integers).

Try this:
SQL
CREATE PROCEDURE UpdateCurrentValueById 
	-- Add the parameters for the stored procedure here
	@ci int = 0, 
	@cv int = 0
AS
BEGIN
	-- SET NOCOUNT ON added to prevent extra result sets from
	-- interfering with SELECT statements.
	SET NOCOUNT ON;

    -- Insert statements for procedure here
	UPDATE Table2 SET [Current_Value] = @cv WHERE [Control_Id] = @ci
	--return updated value
	SELECT @cv = [Current_Value] FROM Table2 WHERE [Control_Id] = @ci
END
GO
 
Share this answer
 
Do you really want to use a static value in your procedure's WHERE clause. What I mean is that instead of
SQL
create procedure update_sam1(@control_id as varchar) as
begin
   update Table_2 set Current_Value=10 where Control_Id=1
end

should you have
SQL
create procedure update_sam1(@control_id as varchar) as
begin
   update Table_2 set Current_Value=10 where Control_Id=@control_id
end

So the parameter passed would control what row is updated. Don't know if this is what you're after but currently you don't use the parameter at all.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900