Solved

Store procedure - Syntax - Why not running properly-- ???

Posted on 2014-10-12
2
443 Views
Last Modified: 2014-10-16
I have the following the code from a book but I'm getting the following error. Not Sure why. I run this into SQL Server Management Studio and create a new store procedure... What I'm missing>sqlManagement
Code:

DROP PROCEDURE IF EXISTS customer_sales
$$
CREATE PROCEDURE customer_sales
        (in_customer_id INT)
   READS SQL DATA
BEGIN
    DECLARE total_sales NUMERIC(8,2);

    SELECT SUM(NumberOfEmployees)
      INTO total_sales
      FROM dbo.Customer
     WHERE CustomerNumber=in_customer_id;

    SELECT CONCAT('Total sales for ',in_customer_id,' is ',total_sales);
END;
$$

Open in new window


Error
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'IF'.
Msg 102, Level 15, State 1, Line 4
Incorrect syntax near 'in_customer_id'.
Msg 155, Level 15, State 2, Line 7
'NUMERIC' is not a recognized CURSOR option.
Msg 195, Level 15, State 10, Line 14
'CONCAT' is not a recognized built-in function name.
0
Comment
Question by:yguyon28
2 Comments
 
LVL 40

Expert Comment

by:Sharath
ID: 40376120
This is not SQL Server sproc. try this if you want to run this in SQL Server.
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID('customer_sales'))
BEGIN
    DROP PROCEDURE customer_sales
END
GO

CREATE PROCEDURE customer_sales 
@in_customer_id INT
AS
    DECLARE @total_sales NUMERIC(8,2);

    SELECT @total_sales = SUM(NumberOfEmployees)
      FROM dbo.Customer
     WHERE CustomerNumber=in_customer_id;

    SELECT 'Total sales for ' + CONVERT(VARCHAR,@in_customer_id) + ' is ' + CONVERT(VARCHAR,@total_sales);

Open in new window

0
 
LVL 10

Accepted Solution

by:
HuaMinChen earned 500 total points
ID: 40376228
Try to use Decimal(12,2) instead of numeric, and ensure that you have created the relevant tables being used by the SP.
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MySQL: Updating SubQuery Match Faster 9 46
SQL Server 2008 R2 - Sums/Grouping 7 51
xampp tool 12 28
Query to return total 6 0
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

867 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

18 Experts available now in Live!

Get 1:1 Help Now