Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Modifying Stored Procedure

Posted on 2011-02-12
7
Medium Priority
?
596 Views
Last Modified: 2012-06-27
I need to Modify the ADD_CUSTOMER procedure below so that it takes a fourth CUST_BALANCE IN argument, including modifying the INSERT statement so that it inserts the value passed in instead of the zero above.  The stored procedure is below.

Please provide assistance - I continue to get error messages

CREATE PROCEDURE ADD_CUSTOMER   -- Create a new customer
   @cus_id_arg NUMERIC,         -- This parameter is the new customer's ID.
   @first_name_arg VARCHAR(30), -- This parameter is the new customer’s first name.
   @last_name_arg VARCHAR(40)   -- This parameter is the new customer's last name.
AS -- This "AS" is required by the syntax of stored procedures.
BEGIN
  -- Insert the new customer with the parameters given, and a 0 balance.
  INSERT INTO CUSTOMER (CUSTOMER_ID,CUSTOMER_FIRST,CUSTOMER_LAST,CUSTOMER_TOTAL)
  VALUES(@cus_id_arg,@first_name_arg,@last_name_arg,0);
END;
0
Comment
Question by:alpha100
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 23

Accepted Solution

by:
wdosanjos earned 1000 total points
ID: 34881170
Give the following a try:

CREATE PROCEDURE ADD_CUSTOMER   -- Create a new customer
   @cus_id_arg NUMERIC,         -- This parameter is the new customer's ID.
   @first_name_arg VARCHAR(30), -- This parameter is the new customer’s first name.
   @last_name_arg VARCHAR(40),   -- This parameter is the new customer's last name.
   @cust_balance money
AS -- This "AS" is required by the syntax of stored procedures.
BEGIN
  -- Insert the new customer with the parameters given, and a 0 balance.
  INSERT INTO CUSTOMER (CUSTOMER_ID,CUSTOMER_FIRST,CUSTOMER_LAST,CUSTOMER_TOTAL)
  VALUES(@cus_id_arg,@first_name_arg,@last_name_arg,@cust_balance);
END;

Open in new window

0
 
LVL 9

Expert Comment

by:gdupadhyay
ID: 34881233
What is the data type of column: CUSTOMER_TOTAL in table:  CUSTOMER?

Please use same datatype as input parameter in stored procedure: ADD_CUSTOMER
Before writing stored procedure, please matched the datatype in table and accept as same data type. You can also type cast,  but it will make more complex.

If datatype is Money, you can use the SP posted by wdosanjos.

If Datatype is decimal: Use this stored procedure.

Or just verify what is exact datatype and use same.
CREATE PROCEDURE ADD_CUSTOMER   -- Create a new customer
   @cus_id_arg			NUMERIC,         -- This parameter is the new customer's ID.
   @first_name_arg		VARCHAR(30), -- This parameter is the new customer’s first name.
   @last_name_arg		VARCHAR(40),   -- This parameter is the new customer's last name.
   @CUST_BALANCE		decimal
   
AS -- This "AS" is required by the syntax of stored procedures.
BEGIN
  -- Insert the new customer with the parameters given, and a 0 balance.
  INSERT INTO CUSTOMER (CUSTOMER_ID, CUSTOMER_FIRST, CUSTOMER_LAST, CUSTOMER_TOTAL)
  VALUES(@cus_id_arg, @first_name_arg, @last_name_arg, @CUST_BALANCE);
END;

Open in new window

0
 
LVL 9

Expert Comment

by:xav056
ID: 34881234
if you are modifying sa stored proc make sure you replace the "CREATE" with "ALTER"
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:alpha100
ID: 34881274
How do I add a row to the store procedure?
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 34881297
What type of row do you want to add?  Please elaborate.
0
 

Author Comment

by:alpha100
ID: 34881331
I have another table called the Item's Table with Item_ID, Item_description, Item_Price.  I need to create a stored procedure that will add additional item row?  I attempted to creat the procedure and received number error messages

Here is what I created:   When I execute I receive error message: Msg 102, Level 15, State 1, Procedure ADD_ITEM, Line 4 Incorrect syntax near 'NUMERIC'.  

What am  I doing wrong?   Thanks


CREATE PROCEDURE ADD_ITEM  -- Create a new item      
   @item_id_arg NUMERIC,         -- This parameter is the new item ID.
   @item_description_arg VARCHAR(30), -- This parameter is the item description.
   @item_price NUMERIC  -- This parameter is the item price.
   
   AS -- This "AS" is required by the syntax of stored procedures.
BEGIN
  -- Insert the new customer with the parameters given, and a 0 balance.
  INSERT INTO item (item_ID,item_description, item_price)
  VALUES(@item_id_arg,@item_description_arg,@item_price_arg,0);
END;
0
 
LVL 23

Expert Comment

by:wdosanjos
ID: 34881346
Change '@item_price NUMERIC' to '@item_price_arg NUMERIC' and remove the 0 on the INSERT statement. These changes should fix it.

If you have related questions, please open another Question.

Thanks.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question