Solved

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

Posted on 2014-10-12
2
451 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 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

Transaction Monitoring Vs. Real User Monitoring

Synthetic Transaction Monitoring Vs. Real User Monitoring: When To Use Each Approach? In this article, we will discuss two major monitoring approaches: Synthetic Transaction and Real User Monitoring.

Question has a verified solution.

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

A recent questions about how to add SSRS named instances, couldn't find any that talks about SQL server 2008, anyway I decided to help by creating some screen shots. The installation is straightforward, you just pop the SQL server 2008 installati…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

688 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