[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 424
  • Last Modified:

Append Update?

Hi All,

Is it possible to 'add' to an existing value within an update statement?

Basically I have the stored procedure below:

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO


ALTER   proc dbo.ash_add_holiday_request(
@start DATETIME,
@end DATETIME,
@hrs FLOAT,
@staff_id INT
)
AS
SET NOCOUNT ON
BEGIN

INSERT INTO dbo.ash_holiday_requests
VALUES(@staff_id, @start, @end,@hrs,0,NULL,0,0)

SELECT IDENT_CURRENT('dbo.ash_holiday_requests')

DECLARE @old_planned_hours =
                  (SELECT hol_planned
                   FROM dbo.ash_holiday
                   WHERE staff_id = @staff_id)

UPDATE dbo.ash_holiday
SET hol_planned = @hrs + @old_planned_hours
WHERE staff_id = @staff_id

END

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO


As you can see, I'm retrieving an existing value of planned_hols so that I can 'add' to it. Is there an easier way of doing this?

Thanks

Jell


0
James Elliott
Asked:
James Elliott
  • 2
1 Solution
 
Jinesh KamdarCommented:
UPDATE dbo.ash_holiday
SET hol_planned = @hrs + hol_planned
WHERE staff_id = @staff_id
0
 
James ElliottManaging DirectorAuthor Commented:
lol, knew it would be simple.

Ty

Jell

0
 
Jinesh KamdarCommented:
Glad to be of help :)
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now