--We created this table for later use
Create table UserLogin
(
UserLoginKey int identity(1,1) primary key,
email nvarchar(255) unique not null,
pwd nvarchar(15) not null
)
go
/*********************************************
* the procedure will register a new donor and
* get the donation
*Check to see if person is in the database
* if they are, update existing information
*If not then enter all the registration information
*Check contact info to determine which ones to write
note for later create a trigger that writes updating information to
a check table
********************************************/
--if the donor schema doesn't exist make it
Create schema Donor
go
--the actual procedure
Create Proc Donor.usp_RegisterDonor
--set up the parameters
@lastname nvarchar (255),
@firstname nvarchar (255),
@Street nvarchar(255),
@Apartment nvarchar(255),
@city nvarchar(255),
@state nvarchar(2) ,
@zip nvarchar(10) ,
@homephone nvarchar(255) ,
@workphone nvarchar(255),
@email nvarchar(255),
@donationAmount money
AS --beginning of procedure body
--declare internal variables
Declare @personkey int
Declare @donationDate Datetime
Set @donationDate=GETDATE()
--insert into person
Insert into Person(FirstName, LastName)
Values(@firstname, @Lastname)
--get the new personkey
Select @personkey =ident_Current('Person')
Insert into PersonAddress(Street, Apartment, [State], City, Zip, PersonKey)
Values(@Street, @Apartment,@state,@city,@zip,@personkey)
--test 1
exec Donor.usp_RegisterDonor
@lastname = 'Jetson',
@firstname ='George',
@Street='10010 North',
@Apartment= null,
@city ='Seattle',
@state ='WA',
@zip ='98188' ,
@homephone=null ,
@workphone=null,
@email =null,
@donationAmount =0
Select * from person
Select * from PersonAddress where PersonKey=52
No comments:
Post a Comment