Saturday, March 19, 2016

Update SQL Stored Procedure in SQL Server


There are situations where a single update query does not solve our problem. To quickly update a table on some conditions we can use below stored procedure to update a table quicly.



Create PROC update_display
(
@price_t numeric(10,2)
)
AS
BEGIN
DECLARE @orderid_t int
DECLARE @max_order_id int
SET @orderid_t = (SELECT min(order_id) from dbo.display_booking)
SET @max_order_id = (SELECT max(order_id) from dbo.display_booking)


while(@orderid_t <= @max_order_id)
BEGIN
update dbo.Display_booking
set price = @price_t
where order_id = @orderid_t;
SET @price_t = @price_t + 100;
SET @orderid_t = @orderid_t + 1;
END
END
GO


exec update_display '1000';



No comments:

Post a Comment