School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,081 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,258 people online right now. Registration is fast and FREE... Join Now!




Need help wit SQL Assignment

 

Need help wit SQL Assignment, SQL Server Help

mxwebb

11 May, 2008 - 08:25 AM
Post #1

New D.I.C Head
*

Joined: 11 May, 2008
Posts: 1

Just started SQL Class and I am struggling with an assignment.
Would someone be kind to give me some help please?

your task is to make a stored procedure that will only billcustomers making monthly payments higher than $500.A Customer can have multiple Plans (services for which they pay amonthly fee).

You have to execute a billing procedure for each single active planunder an eligible customer account. Eligible customer account is anaccount that makes estimated monthly payment higher than $500.

You are given 2 tables, "Customers" and "Plans". Table "Customers" has columns: CustomerID, EmailAddressTable "Plans" has columns: PlanID, CustomerID, MonthlyPrice, isClosed,NextBillDate

Also, you are given two stored procedures named "Bill_Plan" and"Send_Email". All stored procedures returns 0 upon success and negativenumber upon failure.The "Bill_Plan" actually bills a customer for a plan. The storedprocedure takes one input parameter and have one output parameter.

Bill_Plan
@nPlanID = @PlanID,
@dtNewBillDate = @NextBillDate output

You have to use the output parameter @NextBillDate to updatePlans.NextBillDate with its new value.

Upon successful billing you have to send en email to the customer'semail address. The "Send_Email" stored procedure takes two inputparameters.
Send_Email
@sEmailAddress = @EmailAddress,
@sSubject = 'Your Invoice is Ready'
You have to rollback any single billing transaction upon any kind offailure and continue billing the remaining plans. (Important!!!)


OK HERE IS WHAT I HAVE AND I AM STUCK!!
sql

/**********************************************************************
* SP Name: sp_Bill_Cust_monthly_over_500
* Author: Michael Webb
* Date: 05/08/2008
*
*
* Purpose:
* stored procedure that will only billcustomers making monthly payments higher than $500.
* A Customer can have multiple Plans (services for which they pay amonthly fee).
* You have to execute a billing procedure for each single active planunder an eligible customer account.
* Eligible customer account is anaccount that makes estimated monthly payment higher than $500.
* You are given 2 tables, "Customers" and "Plans". Table "Customers" has columns: CustomerID,
* EmailAddressTable "Plans" has columns: PlanID, CustomerID, MonthlyPrice, isClosed,NextBillDate Also,
* you are given two stored procedures named "Bill_Plan" and"Send_Email".
* All stored procedures returns 0 upon success and negativenumber upon failure.
* The "Bill_Plan" actually bills a customer for a plan. The storedprocedure takes one input parameter
* and have one output parameter. Bill_Plan@nPlanID = @PlanID,@dtNewBillDate = @NextBillDate
* output You have to use the output parameter @NextBillDate to updatePlans.NextBillDate with its
* new value. Upon successful billing you have to send en email to the customer'semail address.
* The "Send_Email" stored procedure takes two inputparameters. Send_Email@sEmailAddress = @EmailAddress,
* @sSubject = 'Your Invoice is Ready' You have to rollback any single billing transaction upon any
* kind offailure and continue billing the remaining plans. (Important!!!)
*
**********************************************************************

*
*/

if exists( select * from sysobjects where name='sp_Bill_Cust_monthly_over_500' and type='P' )
drop proc sp_Bill_Cust_monthly_over_500
go

CREATE PROCEDURE sp_Bill_Cust_monthly_over_500
AS



/***************************
** Variable declarations **
***************************
*/

declare @tc int /* tran count */
declare @nPlanID int
declare @dtNewBillDate
declare @sEmailAddress varchar(100)
declare @sSubject varchar (100)
Set @sSubject = 'Your Invoice is Ready'

/*******************************************************************
** Check whether to start a new transaction, or save the old one
*******************************************************************
*/

select @tc = @@trancount
if ( @tc > 0 )
save tran my_tran
else
begin tran my_tran


/********************************************************************
** PLACE YOUR PROCEDURE CODE HERE **
********************************************************************
*/
Declare BillCur Cursor

For

Select P.PlanID, C.EmailAddress
From customer C
INNER JOIN plans P on c.customerID = p.customerID
Where P.MonthlyPrice > 500
and P.isclose = 0


Open BillCur
Fetch Next From Cursor Into @nPlanID, @sEmailAddress
Bill_Plan( @nPlanID)


End

/********************************************************************
** Transaction was successful
** - Commit if this procedure issued a begin tran
********************************************************************
*/

if ( @tc = 0 )
commit tran my_tran

return 0

go

GRANT EXECUTE ON sp_Bill_Cust_monthly_over_500


This post has been edited by PsychoCoder: 21 May, 2008 - 05:49 PM

User is offlineProfile CardPM
+Quote Post


jjsaw5

RE: Need Help Wit SQL Assignment

12 May, 2008 - 04:09 AM
Post #2

I must break you
Group Icon

Joined: 4 Jan, 2008
Posts: 2,664



Thanked: 25 times
Dream Kudos: 125
My Contributions
Just for future reference, please you [code] tags.

Thanks and Good Luck!
User is offlineProfile CardPM
+Quote Post

mikeblas

RE: Need Help Wit SQL Assignment

21 May, 2008 - 04:55 PM
Post #3

D.I.C Regular
Group Icon

Joined: 8 Feb, 2008
Posts: 390



Thanked: 27 times
My Contributions
QUOTE(mxwebb @ 11 May, 2008 - 09:25 AM) *

OK HERE IS WHAT I HAVE AND I AM STUCK!!
What's your specific question?

User is offlineProfile CardPM
+Quote Post

PsychoCoder

RE: Need Help Wit SQL Assignment

21 May, 2008 - 05:54 PM
Post #4

I Code, Therefore I am
Group Icon

Joined: 26 Jul, 2007
Posts: 14,931



Thanked: 517 times
Dream Kudos: 11550
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net, jQuery

My Contributions
I'm with Mike, you say you're stuck but give no explanation. Are you receiving any errors, if so what are they? What is this code doing versus what you want/need it to do? These are vital pieces of information needed to help us help you. You cannot just post code and expect us to figure out what you want or what's going wrong smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 10:34AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month