消息 102,级别 15,状态 1,过程 spProductsTop,第 32 行?????
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"。