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.
Author |
Topic |
trouble2
Constraint Violating Yak Guru
267 Posts |
Posted - 2011-08-30 : 05:00:58
|
Hi I need to updata a table with a column which has the number of places available for a booking.So I can use a @numberofplaces int and then need to have some check likeif PlacesAvailble >= @numberofplaces then PlacesAvailable = PlacesAvailable - @NumberOfPlaces return trueelse return falseend ifAnd I also think you need to lock the record for the duration of the update.How can I do that? |
|
trouble2
Constraint Violating Yak Guru
267 Posts |
Posted - 2011-08-30 : 05:17:17
|
So far I've gotALTER PROCEDURE [dbo].[DemoDate_UpdateAvailable] @DateID int, @NumberOfSeats intASBegin if exists(select * from dbo.DemoDate where [NumberOfSeatsAvailable] >= @NumberOfSeats and DemoDateID = @DateID ) begin update dbo.DemoDate set [NumberOfSeatsAvailable] = [NumberOfSeatsAvailable] - @NumberOfSeats where DemoDateID = @DateID select 1 end else select 0EndThe secret to creativity is knowing how to hide your sources. (Einstein) |
|
|
trouble2
Constraint Violating Yak Guru
267 Posts |
Posted - 2011-08-30 : 05:17:50
|
So how can I lock the recordThe secret to creativity is knowing how to hide your sources. (Einstein) |
|
|
|
|
|