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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Copy selected record

Author  Topic 

Pinto
Aged Yak Warrior

590 Posts

Posted - 2005-10-31 : 09:58:49
I want to copy a record to a new record in the same table, changing one of the fields. My sp below is doing this, but is also changing the value BookingNo in my record I am copying from, to the new @strBookingNo that I want in my new record. The purpose of this operation is that I have a menu order that my user can select to repeat. So, I just want to copy the original order to a new one, just changing the BookingNo to the new number. The sp is called from a webpage.

CREATE PROCEDURE spRB_CopyMenuBooking

@strBookingNotoCopy int,
@strBookingNo int

AS

INSERT INTO tblRB_MenuBookings(
MB_BookingNo,
MB_Item,
MB_TimeRequired,
MB_LedgerCode,
MB_NoFor)


SELECT
@strBookingNo,
MB_Item,
MB_TimeRequired,
MB_LedgerCode,
MB_NoFor
from tblRB_MenuBookings
WHERE MB_BookingNo = @strBookingNotoCopy
GO

nathans
Aged Yak Warrior

938 Posts

Posted - 2005-10-31 : 13:26:25
How do you populate @strBookingNo ?

You should only be passing in @strBookingNotoCopy, then use an identity or similar routine to generate the "new" column MB_BookingNo.

If you are passing in a unique MB_BookingNo as strBookingNo you should be doing a new row insert. I dont see where you would be updating the existing record in this code.


Nathan Skerl
Go to Top of Page
   

- Advertisement -