Solved

Stored Procedure

Posted on 2011-02-13
2
203 Views
Last Modified: 2012-05-11
I need to update this Stored Procedure by adding a row. Please Advise

 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;

I changed the arugment '@item_price NUMERIC' to '@item_price_arg NUMERIC' and remove the 0 on the INSERT statement.

I am still receiving INcorrect syntax error.
0
Comment
Question by:alpha100
2 Comments
 
LVL 16

Assisted Solution

by:BurnieP
BurnieP earned 250 total points
ID: 34882926
Hi,

I have made some modifications to your code.  See if you get better results.  I changed numeric to int and removed the ,0 in the VALUES.
CREATE PROCEDURE ADD_ITEM  -- Create a new item      
   @item_id_arg int,         -- This parameter is the new item ID.
   @item_description_arg VARCHAR(30), -- This parameter is the item description.
   @item_price decimal(18,2)  -- 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);
END;

Open in new window

0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 250 total points
ID: 34883878
Try it this way:

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);
END;

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Long way back, we had to take help from third party tools in order to encrypt and decrypt data.  Gradually Microsoft understood the need for this feature and started to implement it by building functionality into SQL Server. Finally, with SQL 2008, …
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now