Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Delete and insert in the same sp

Author  Topic 

Pinto
Aged Yak Warrior

590 Posts

Posted - 2005-11-15 : 11:12:53
Here's my sp. Before I insert my new values I want to delete the existing records from the table. Can I do this in the same sp ? If so, could someone tell me the syntax please.

CREATE PROCEDURE [spRB_AddBlockBookingDateRef]

** here Delete * from tblRB_BlockBookingDates

@strBookingDateRef nvarchar(100),
@strRoomRef nvarchar (50),
@strDateRequired datetime

AS

INSERT INTO tblRB_BlockBookingDates(
BB_BookingDateRef,
BB_RoomRef,
BB_DateRequired)


VALUES
(@strBookingDateRef,
@strRoomRef,
@strdateRequired
)
GO

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-11-15 : 11:50:51
...
AS

delete from tblRB_BlockBookingDates where you condition

insert into ....

Go with the flow & have fun! Else fight the flow
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2005-11-15 : 11:52:28
I don't need a 'WHERE' I want to delete all the records.
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2005-11-15 : 11:54:56
well then just do
delete from tblRB_BlockBookingDates

Go with the flow & have fun! Else fight the flow
Go to Top of Page

Vivaldi
Constraint Violating Yak Guru

298 Posts

Posted - 2005-11-15 : 12:25:37
truncate table tblRB_BlockBookingDates
go
INSERT INTO tblRB_BlockBookingDates(
BB_BookingDateRef,
BB_RoomRef,
BB_DateRequired)


VALUES
(@strBookingDateRef,
@strRoomRef,
@strdateRequired
)

________________________________________________

SQL = Serious Quaffing of Liquor
Go to Top of Page

Pinto
Aged Yak Warrior

590 Posts

Posted - 2005-11-16 : 04:28:00
Many thanks - it's working fine now.
Go to Top of Page
   

- Advertisement -