Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

How do I calculate this? Expand / Collapse
Author
Message
Posted Monday, May 27, 2013 6:15 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Saturday, March 15, 2014 7:36 PM
Points: 182, Visits: 705
I have a table called locations with fieldnames:

locationId --determines the location of trainee
locationName --name of the location training
maxSeat --total number of seats allowed at that location.
available_seats -- (MaxSeat - registered trainees)

My question is:

We would like to a button that says "Register" to substract a number from MaxSeat and "Cancel" to put back a number to MaxSeat.

In other words, when a potential trainee registers for a class, we would like to substract a number from maxSeat.

For instance, maxSeat is 45. If a trainee registers for that class, we would substract 1 from maxSeat.

Example: if maxSeat is 45 and a new trainee registers, we would like to see available seat as 44.

If another trainee registers, available seat should read 43, etc.

If a trainee decides to cancel a seat, this puts back a seat to availlable_seat so that it now goes up by one.

How can I code this?

Thanks a lot
Post #1457161
Posted Monday, May 27, 2013 11:22 PM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-Dedicated

Group: General Forum Members
Last Login: Yesterday @ 10:03 PM
Points: 35,956, Visits: 30,244
Create another value somewhere that is a copy of the MAX. Increment and decrement that with the idea that "returns" will never drive the number over the MAX and "draws" will ever decremet the number below 0.

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

"Change is inevitable. Change for the better is not." -- 04 August 2013
(play on words) "Just because you CAN do something in T-SQL, doesn't mean you SHOULDN'T." --22 Aug 2013

Helpful Links:
How to post code problems
How to post performance problems
Post #1457186
Posted Tuesday, May 28, 2013 6:50 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Saturday, March 15, 2014 7:36 PM
Points: 182, Visits: 705
Thanks Jeff.
Post #1457294
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse