Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

restricting any loaner from borrowing unreturned Item

$
0
0

Hiii

I have a loan table with 4 columns in SQL . GeneralID (items am loaning my frnds), LoanerID (People who long my staff), DateLoaned (a date I loaned a frnd an item) and DateReturned (a date he/she returned that particular item).

the table must allow a person to loan different items many times, but the person cant loan the same item at the same time. which means in order for the same person or different person to loan an item that is not returned, the item must be returned.

if the Date-returned is null it mean the item is not returned and if the Date-returned has a Date value it means the item is returned and it can be loaned again as long as it is available. a date-loaned must not be null.

so in my code:

many user can loan the same GeneralID which is wrong.

here's my sql code and c# code:

create store procedure:


ALTER

Procedure [dbo].[CreateLoans]

@GeneralID

int,

@LoanerID

int,

@DateLoaned Date,

@DateReturned Date

AS

begin

insert

into dbo.Loans

(

GeneralID, LoanerID, [Date Loaned], [Date Returned])

Values

(@GeneralID, @LoanerID, @DateLoaned, @DateReturned)

end

;


Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>