?
Solved

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

Posted on 2014-10-12
2
Medium Priority
?
454 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
[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
2 Comments
 
LVL 41

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 11

Accepted Solution

by:
HuaMinChen earned 2000 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

777 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