尝试在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;
谢谢,我真的很感激任何帮助。
答案 0 :(得分:2)
改变这个:
CREATE PROCEDURE sql_chp4a_premiere_assign
到此:
CREATE PROCEDURE sql_chp4a_premiere_assign AS
答案 1 :(得分:1)
第一:
这部分你错了:
USE [school username that gives out my name)
将)
更改为]
:
USE [school username that gives out my name]
第二
您在存储过程声明中缺少AS
,BEGIN
和END
关键字。
第三
您创建了两个存储过程。使用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
有关存储过程的语法,请参阅here。
无论如何,您可以使用this格式化SQL。
答案 2 :(得分: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