这是我应该可以回答这个问题:为什么我得到这个SQL脚本的错误?
- 编写使用两个变量来存储(1)在产品的所有产品的计数脚本表和(2)这些产品的平均标价。如果产品数量大于或等于7,则脚本应该打印显示两个变量值的消息。否则,该脚本应打印一条消息,指出“产品数量少于7个”。
这里是我的SQL语句:
USE MyGuitarShop;
DECLARE @AllProduct2 INT;
DECLARE @AvgAllListPrice MONEY;
SET @AllProduct2 = (SELECT COUNT(ProductID) FROM Products);
SET @AvgAllListPrice = (SELECT AVG (ListPrice) FROM Products);
IF @AllProduct2 > 7
BEIGN
PRINT 'The number of products is greater than or equal to 7';
PRINT 'The average list price for the products is $' + CONVERT (varchar,@AvgAllListPrice,1);
END;
ELSE
PRINT 'The number of products is less than 7';
我在做什么错误或我缺少什么?
EDIT
对不起,不添加错误:
消息102,级别15,状态1,行8 附近有语法错误BEIGN'。 Msg 102,Level 15,State 1,Line 11 ';'附近语法不正确。
我结束了由返工我的代码修复它:
USE MyGuitarShop;
DECLARE @AllProduct2 INT;
DECLARE @AvgListPrice MONEY;
SELECT @AllProduct2 = COUNT(ProductID),
@AvgListPrice = AVG (ListPrice)
FROM Products
IF @AllProduct2 > 7
BEGIN
PRINT 'The number of products is greater than or equal to 7';
PRINT 'The average list price is $' + CONVERT (VARCHAR, @AvgListPrice,1) + '.';
END;
ELSE
PRINT 'The number of products is less than 7';
对不起再次感谢那些谁帮我出!!!!!
Incorrecting拼写BEIGN –
拼写错误和错误是什么? –
当问一个关于为什么代码*不工作的问题时,如果包含错误信息,以及您所得到的行为和您期望的行为,这会非常有帮助。 – AdamMc331