0

我正在将参数从 asp.net webform 传递给存储过程。

然而,对于一个特定的参数组合,单个参数似乎被忽略了。

我传递的导致问题的参数如下:

EXEC    @return_value = [dbo].[spProgressCohorts]
    @StuYear = N'10',
    @DataCollection = N'March 2013 Teacher Assessments',
    @SubjectName = N'English',
    @TeachingGroup = N'Select All',
    @Subgroup = N'Select All',
    @KS2 = '',
    @Result = ''

当我使用这些参数运行存储过程时,结果返回就好像 @Result 变量被忽略了一样。

存储过程返回的结果是(包含 ks2en 和 result 列以供参考):

surname     forename    ks2en   result
El Hajj     Zeinab              D
Grzelak     Marlena             F+
Sage        Nigel       

但是,当我运行以下查询时,我只得到了 Nigel Sage 的记录(正如预期的那样,这是存储过程应该返回的):

select surname, forename, ks2en, result 
    from student join subject on subject.upn=student.upn 
where datacollection='March 2013 Teacher Assessments' and stuyear='10' and name='english' and result='' and ks2en=''

我的存储过程很庞大,所以我只包含特定于上述参数的代码:

ALTER PROCEDURE [dbo].[spProgressCohorts]
    @StuYear varchar(2),  
    @DataCollection varchar(100), 
    @SubjectName varchar(100), 
    @TeachingGroup varchar(30), 
    @Subgroup varchar(10), 
    @Result varchar(4), 
    @KS2 varchar(4)

AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
 --interfering with SELECT statements.
SET NOCOUNT ON;

SELECT Forename + ' ' + Surname

FROM student
   JOIN subject
     ON subject.upn = student.upn
WHERE 
    (@StuYear = [stuyear]
    AND @TeachingGroup = 'Select All'
    AND [DataCollection] = @DataCollection
    AND [Name] = @SubjectName
    AND @Subgroup='Select All'
    AND @KS2 = CASE @subjectName WHEN 'English' THEN KS2en WHEN 'Mathematics' THEN KS2ma ELSE KS2av END
    AND [Result] like @Result + '%')
OR 
    (@StuYear = [stuyear]
        AND @TeachingGroup Not Like 'Select All'
        AND [DataCollection] = @DataCollection
        AND [Name] = @SubjectName
        AND [TeachingGroup] = @TeachingGroup
        AND @Subgroup='Select All'
        AND @KS2 = CASE @subjectName WHEN 'English' THEN KS2en WHEN 'Mathematics' THEN KS2ma ELSE KS2av END
        AND [Result] like @Result + '%')

ORDER BY surname, forename
4

1 回答 1

1

这个怎么样?

...
AND [Result] LIKE CASE @Result WHEN '' THEN '' ELSE @Result + '%' END)
于 2013-06-18T11:57:00.693 回答