Possible Duplicate:
SELECT FROM stored procedure?
How should I include a stored procedure in a T-SQL syntax?
select * from CITY_TABLE C where
COUNT_PEOPLE_PROCEDURE(C.ID) > 3
Possible Duplicate:
SELECT FROM stored procedure?
How should I include a stored procedure in a T-SQL syntax?
select * from CITY_TABLE C where
COUNT_PEOPLE_PROCEDURE(C.ID) > 3
您不能像这样将存储过程包含在查询中。
相反,您可以制作标量函数
create function COUNT_PEOPLE_FUNCTION
(
@ID int
)
returns int
as
begin
declare @Result int
<... your code here ...>
return @Result
end
接着
select * from CITY_TABLE C where COUNT_PEOPLE_FUNCTION(C.ID) > 3
但是,实际上,它可能会减慢您的查询速度,因为将为每一行单独调用标量函数。
根据您的评论,如果您需要获取仅有 n 个出现的记录,您可以使用这样的子查询:
SELECT * FROM CITY_TABLE WHERE IDPerson IN (
SELECT IDPerson FROM CITY_TABLE GROUP BY IDPerson HAVING COUNT(*) > 3
)
显然我不知道确切的列名,但这是我的想法。
正如其他人已经说过的那样,您不能使用这样的存储过程,我建议您尽可能使用函数;如果您不能使用函数(即使可以),我建议您将此页面作为有用的阅读材料: