-1

尝试在 SQL Server 中执行时,我不断收到错误消息:

消息 156,级别 15,状态 1,过程 sql_chp4a_premiere_assign,第 5 行
关键字“SELECT”附近的语法不正确。

我认为它指的是第一个SELECT. 我对 SQL 还不是很熟悉(以及由于可怕的风暴和春假而有一段时间没有上课)所以这可能是我忽略的一些愚蠢的事情。

USE [school username that gives out my name)

CREATE PROCEDURE sql_chp4a_premiere_assign

SELECT PART_NUM,DESCRIPTION,PRICE 
FROM PART;

SELECT *
FROM ORDERS

SELECT CUSTOMER_NAME 
FROM customer 
WHERE CREDIT_LIMIT>=10000;

SELECT ORDER_NUM
FROM ORDERS
WHERE CUSTOMER_NUM = '608'
AND ORDER_DATE = '2010-10-23';

SELECT CUSTOMER_NUM,CUSTOMER_NAME 
FROM CUSTOMER 
WHERE REP_NUM=35 OR REP_NUM=65;

SELECT PART_NUM,DESCRIPTION 
FROM PART WHERE CLASS!='AP';

SELECT PART_NUM,DESCRIPTION,ON_HAND 
FROM PART 
WHERE ON_HAND BETWEEN 10 AND 25;

SELECT PART_NUM,DESCRIPTION,ON_HAND 
FROM PART 
WHERE ON_HAND>=10 AND ON_HAND<=25;

SELECT PART_NUM,DESCRIPTION,(ON_HAND * PRICE) 
AS "ON_HAND_VALUE" 
FROM PART WHERE CLASS='SG';

SELECT PART_NUM,DESCRIPTION,(ON_HAND * PRICE) 
AS "ON_HAND_VALUE" 
FROM PART 
WHERE (ON_HAND * PRICE)>7500;

SELECT PART_NUM,DESCRIPTION,(ON_HAND * PRICE) 
AS "ON_HAND_VALUE" 
FROM PART WHERE (ON_HAND * PRICE)>7500;

谢谢,我真的很感激任何帮助。

4

3 回答 3

2

改变这个:

CREATE PROCEDURE sql_chp4a_premiere_assign

对此:

CREATE PROCEDURE sql_chp4a_premiere_assign AS
于 2013-03-26T02:49:16.343 回答
1

第一的:

你在这部分错了:

USE [school username that gives out my name)

更改)]

USE [school username that gives out my name]

第二:

您在存储过程声明中缺少AS,BEGINEND关键字。

第三:

您创建了两个存储过程。用分隔每个存储过程声明GO

这将起作用:

USE [school username that gives out my name]

go

CREATE PROCEDURE Sql_chp4a_premiere_assign
AS
  BEGIN
      SELECT part_num,
             description,
             price
      FROM   part;

      SELECT *
      FROM   orders

      SELECT customer_name
      FROM   customer
      WHERE  credit_limit >= 10000;

      SELECT order_num
      FROM   orders
      WHERE  customer_num = '608'
             AND order_date = '2010-10-23';

      SELECT customer_num,
             customer_name
      FROM   customer
      WHERE  rep_num = 35
              OR rep_num = 65;

      SELECT part_num,
             description
      FROM   part
      WHERE  class != 'AP';

      SELECT part_num,
             description,
             on_hand
      FROM   part
      WHERE  on_hand BETWEEN 10 AND 25;

      SELECT part_num,
             description,
             on_hand
      FROM   part
      WHERE  on_hand >= 10
             AND on_hand <= 25;

      SELECT part_num,
             description,
             ( on_hand * price ) AS "ON_HAND_VALUE"
      FROM   part
      WHERE  class = 'SG';

      SELECT part_num,
             description,
             ( on_hand * price ) AS "ON_HAND_VALUE"
      FROM   part
      WHERE  ( on_hand * price ) > 7500;

      SELECT part_num,
             description,
             ( on_hand * price ) AS "ON_HAND_VALUE"
      FROM   part
      WHERE  ( on_hand * price ) > 7500;
  END;

go

CREATE PROCEDURE Sql_chp4a_premiere_assign
AS
  BEGIN
      SELECT part_num,
             description,
             price
      FROM   part;

      SELECT *
      FROM   orders

      SELECT customer_name
      FROM   customer
      WHERE  credit_limit >= 10000;

      SELECT order_num
      FROM   orders
      WHERE  customer_num = '608'
             AND order_date = '2010-10-23';

      SELECT customer_num,
             customer_name
      FROM   customer
      WHERE  rep_num = 35
              OR rep_num = 65;

      SELECT part_num,
             description
      FROM   part
      WHERE  class != 'AP';

      SELECT part_num,
             description,
             on_hand
      FROM   part
      WHERE  on_hand BETWEEN 10 AND 25;

      SELECT part_num,
             description,
             on_hand
      FROM   part
      WHERE  on_hand >= 10
             AND on_hand <= 25;

      SELECT part_num,
             description,
             ( on_hand * price ) AS "ON_HAND_VALUE"
      FROM   part
      WHERE  class = 'SG';

      SELECT part_num,
             description,
             ( on_hand * price ) AS "ON_HAND_VALUE"
      FROM   part
      WHERE  ( on_hand * price ) > 7500;

      SELECT part_num,
             description,
             ( on_hand * price ) AS "ON_HAND_VALUE"
      FROM   part
      WHERE  ( on_hand * price ) > 7500;
  END  

有关存储过程的语法,请参见此处

无论如何,您可以使用来格式化您的 SQL。

于 2013-03-26T02:51:03.117 回答
0

尝试这个

CREATE PROCEDURE sql_chp4a_premiere_assign
AS 
BEGIN
    SELECT PART_NUM,DESCRIPTION,PRICE 
    FROM PART;

    SELECT *
    FROM ORDERS

    SELECT CUSTOMER_NAME 
    FROM customer 
    WHERE CREDIT_LIMIT>=10000;

    SELECT ORDER_NUM
    FROM ORDERS
    WHERE CUSTOMER_NUM = '608'
    AND ORDER_DATE = '2010-10-23';

    SELECT CUSTOMER_NUM,CUSTOMER_NAME 
    FROM CUSTOMER 
    WHERE REP_NUM=35 OR REP_NUM=65;

    SELECT PART_NUM,DESCRIPTION 
    FROM PART WHERE CLASS!='AP';

    SELECT PART_NUM,DESCRIPTION,ON_HAND 
    FROM PART 
    WHERE ON_HAND BETWEEN 10 AND 25;

    SELECT PART_NUM,DESCRIPTION,ON_HAND 
    FROM PART 
    WHERE ON_HAND>=10 AND ON_HAND<=25;

    SELECT PART_NUM,DESCRIPTION,(ON_HAND * PRICE) 
    AS "ON_HAND_VALUE" 
    FROM PART WHERE CLASS='SG';

    SELECT PART_NUM,DESCRIPTION,(ON_HAND * PRICE) 
    AS "ON_HAND_VALUE" 
    FROM PART 
    WHERE (ON_HAND * PRICE)>7500;

    SELECT PART_NUM,DESCRIPTION,(ON_HAND * PRICE) 
    AS "ON_HAND_VALUE" 
    FROM PART WHERE (ON_HAND * PRICE)>7500;
END
于 2013-03-26T05:48:04.370 回答