我试图构建一个使用另一个存储过程的存储过程。将其结果作为where子句的一部分使用,由于某种原因我收到错误:tsql - 使用内部存储过程作为参数是where子句
无效的对象名称'dbo.GetSuitableCategories'。
下面是代码的副本:
select distinct top 6 * from
(
SELECT TOP 100 *
FROM [dbo].[products] products
where products.categoryId in
(select top 10 categories.categoryid from
[dbo].[GetSuitableCategories]
(
-- @Age
-- ,@Sex
-- ,@Event
1,
1,
1
) categories
ORDER BY NEWID()
)
--and products.Price <[email protected]
ORDER BY NEWID()
)as d
union
select * from
(
select TOP 1 * FROM [dbo].[products] competingproducts
where competingproducts.categoryId =-2
--and competingproducts.Price <[email protected]
ORDER BY NEWID()
) as d
,这里是[DBO] [GetSuitableCategories]:
if (@gender =0)
begin
select * from categoryTable categories
where categories.gender =3
end
else
begin
select * from categoryTable categories
where categories.gender = @gender
or categories.gender =3
end
你也可以创建一个返回您请求,如果数据的视图所有GetSuitableCategories SP都会运行Select语句。 – heartlandcoder 2010-05-16 05:57:39