计数记录我为计数过滤的搜索记录的存储过程(见下面)从过滤的搜索
但是,如果我做了场“academiejaar”过滤的搜索存储过程(学年)和'studierichting'(当然),我得到一个错误的数字。
这是我的存储过程:
@voornaam nvarchar(50) = null,
@naam varchar(50) = null,
@studierichting varchar(50) = null,
@academiejaar varchar(9) = null,
@gastinstelling nvarchar(100) = null,
@periode varchar(50) = null,
@recordCount int = NULL OUTPUT
AS
IF (@recordCount IS NOT NULL)
BEGIN
SET @recordCount = (SELECT
COUNT(*) FROM Studenten
INNER JOIN Curriculum
ON Studenten.id=Curriculum.studentid
INNER JOIN erasmus
ON Studenten.id=erasmus.studentid
WHERE
([studenten].voornaam LIKE '%' + @voornaam + '%' OR @voornaam IS NULL)
AND ([studenten].naam LIKE '%' + @naam + '%' OR @naam IS NULL)
AND ([erasmus].academiejaar = @academiejaar OR @academiejaar IS NULL)
AND ([erasmus].gastinstelling LIKE '%' + @gastinstelling + '%' OR @gastinstelling IS NULL)
AND ([erasmus].periode = @periode OR @periode IS NULL)
AND ([curriculum].studierichting_vorig LIKE '%' + @studierichting + '%' OR @studierichting IS NULL))
RETURN
END
我是从这个存储过程取回计数是非常高的。我得到39的recordCount,而它应该是8
有没有人在这个sql查询中看到一个错误?
感谢您的帮助,
安东尼 比利时
嗨约杰什,感谢您的帮助,我想你的代码,如果我在SQL Server Management Studio中执行存储过程,我得到记录的确切数目,8:使用[erasmusmanager] GO DECLARE \t @return_value INT, \t \t @recordCount INT EXEC \t @return_value = [DBO] [sprocStudentSearchList] 01。\t @studierichting = N'sociologie ' \t \t @academiejaar = N'2011-2012' , \t \t @recordCount = @recordCount OUTPUT SELECT \t @recordCount如N '@的RecordCount' SELECT \t' 返回值'= @return_value 但是,如果在我的web应用程序中,记录数仍然是39.有点让我疯了! Anthony – Toontje
如果存储过程在SSMS中给出的确切结果比在应用程序中给出相同的结果。你能提供你的应用程序代码获取这个商店程序的结果吗? –