消息 102,级别 15,状态 1,过程 spProductsTop,第 32 行?????

feifeiyaqi3 2007-07-28 09:38:34
create procedure spProductsTop
(@top varchar(25),
@orderby varchar(50),
@categoryId varchar(25)

)
as
set nocount on
--select top +@top o.* ,s.Name as categoryName ,p.name as vendor from product o
--inner join categories s on o.categoryId=s.Id inner join customers p on o.vendor=p.id

declare @ssql varchar(500)
select @sSql='select top'+@top
select @sSQL=@sSql+'o.*,s.Name as CategoryName,'
select @sSQL=@sSql+ 'p.Name as Vendor'
select @sSQL=@sSql+ 'from Products o inner join '

select @sSQL=@sSql+ 'categories s on o.CategoryId=s.Id inner join '
select @sSQL=@sSql+'Customers p on o.VendorId=p.Id'

if cast(@CategoryId as int)>=0
begin
select @sSQL=@sSQL +'where o.CategoryID='+@CategoryId
end
if @orderBy <>'DateTimed'
select @sSql=@sSql+'Order by o.'+@Orderby +' desc ,o.DateTimed desc &'
else
select @sSql=@sSql+ 'order by o'+@orderby +'desc'
exec (@sSql)

set nocount off
******************************
( @cartId nvarchar(25)) 此句就是错误之处?????
******************************
as
SELECT A.ProductID, A.ModelName, A.ModelNumber, B.Quantity,
A.UnitCost, CAST(A.UnitCost * B.Quantity AS money) AS ExtendedAmount
FROM dbo.Products A INNER JOIN
dbo.ShoppingCart B ON A.ProductID = B.ProductID
WHERE (B.CartID = @CartID)
ORDER BY A.ModelName, A.ModelNumber


错误提示为:
消息 102,级别 15,状态 1,过程 spProductsTop,第 32 行
'@cartId' 附近有语法错误。
消息 137,级别 15,状态 2,过程 spProductsTop,第 38 行
必须声明标量变量 "@CartID"。

...全文
882 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
feifeiyaqi3 2007-07-29
  • 打赏
  • 举报
回复
create procedure spProductsTop
(@top varchar(25),
@orderby varchar(50),
@categoryId varchar(25),
@cartId nvarchar(25)

)
error ??????????????????????
bote_china 2007-07-28
  • 打赏
  • 举报
回复
这个存储过程应该返回了2个行集
create procedure spProductsTop
(@top varchar(25),
@orderby varchar(50),
@categoryId varchar(25),
@cartId nvarchar(25)

)
as
set nocount on
--select top +@top o.* ,s.Name as categoryName ,p.name as vendor from product o
--inner join categories s on o.categoryId=s.Id inner join customers p on o.vendor=p.id

declare @ssql varchar(500)
select @sSql='select top'+@top
select @sSQL=@sSql+'o.*,s.Name as CategoryName,'
select @sSQL=@sSql+ 'p.Name as Vendor'
select @sSQL=@sSql+ 'from Products o inner join '

select @sSQL=@sSql+ 'categories s on o.CategoryId=s.Id inner join '
select @sSQL=@sSql+'Customers p on o.VendorId=p.Id'

if cast(@CategoryId as int)>=0
begin
select @sSQL=@sSQL +'where o.CategoryID='+@CategoryId
end
if @orderBy <>'DateTimed'
select @sSql=@sSql+'Order by o.'+@Orderby +' desc ,o.DateTimed desc &'
else
select @sSql=@sSql+ 'order by o'+@orderby +'desc'
exec (@sSql)

set nocount off

SELECT A.ProductID, A.ModelName, A.ModelNumber, B.Quantity,
A.UnitCost, CAST(A.UnitCost * B.Quantity AS money) AS ExtendedAmount
FROM dbo.Products A INNER JOIN
dbo.ShoppingCart B ON A.ProductID = B.ProductID
WHERE (B.CartID = @CartID)
ORDER BY A.ModelName, A.ModelNumber
feifeiyaqi3 2007-07-28
  • 打赏
  • 举报
回复
create procedure spProductsTop
(@top varchar(25),
@orderby varchar(50),
@categoryId varchar(25)

)
as
set nocount on
--select top +@top o.* ,s.Name as categoryName ,p.name as vendor from product o
--inner join categories s on o.categoryId=s.Id inner join customers p on o.vendor=p.id

declare @ssql varchar(500)
select @sSql='select top'+@top
select @sSQL=@sSql+'o.*,s.Name as CategoryName,'
select @sSQL=@sSql+ 'p.Name as Vendor'
select @sSQL=@sSql+ 'from Products o inner join '

select @sSQL=@sSql+ 'categories s on o.CategoryId=s.Id inner join '
select @sSQL=@sSql+'Customers p on o.VendorId=p.Id'

if cast(@CategoryId as int)>=0
begin
select @sSQL=@sSQL +'where o.CategoryID='+@CategoryId
end
if @orderBy <>'DateTimed'
select @sSql=@sSql+'Order by o.'+@Orderby +' desc ,o.DateTimed desc &'
else
select @sSql=@sSql+ 'order by o'+@orderby +'desc'
exec (@sSql)

set nocount off
*****************
declare @cartId nvarchar(25) 此句是错误的东西???
*********************
消息 156,级别 15,状态 1,过程 spProductsTop,第 35 行
关键字 'as' 附近有语法错误。

as
SELECT A.ProductID, A.ModelName, A.ModelNumber, B.Quantity,
A.UnitCost, CAST(A.UnitCost * B.Quantity AS money) AS ExtendedAmount
FROM dbo.Products A INNER JOIN
dbo.ShoppingCart B ON A.ProductID = B.ProductID
WHERE (B.CartID = @CartID)
ORDER BY A.ModelName, A.ModelNumber
yygyogfny 2007-07-28
  • 打赏
  • 举报
回复
我也是,看了半天也没看到这个变量的定义.
RHCL 2007-07-28
  • 打赏
  • 举报
回复
LZ好像没有声明@CartID...这个都没发现你在哪声明有...
yygyogfny 2007-07-28
  • 打赏
  • 举报
回复
@cartId nvarchar(25))是变量还是参数?
如果是变量就要定义啊,declare @CartId nvarchar(25)

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧