我可能会问这个问题是错的,但这就是我要做的事情:
我的SP中有以下select语句。我将在SSRS中使用此语句,以便用户通过参数传递值。但是,我的问题是我能想到的唯一参数是Status
参数。我使用case语句创建了一个计算列。
我希望SSRS中的用户选择一个值:已发布,未发布或全部。
如何使用计算的列和状态执行此操作?
注意: SIS.cs_id_number和PC.css_id是整数值。
BEGIN
SELECT PC.css_id as [CSS ID]
, convert(VARCHAR, PC.birth_date, 101) AS DOB
, PC.first_name as [First Name]
, PC.last_name as [Last Name]
, ssn as [SSN]
, substring(PC.css_record, CHARINDEX('<AddressLine>', PC.css_record) + 22,CHARINDEX('</AddressLine>', PC.css_record)- CHARINDEX('<AddressLine>', PC.css_record) - 25) as [Street]
, City
, substring(PC.css_record, CHARINDEX('<StateProvinceCode>', PC.css_record) + 19 , 2 ) + ' - ' + substring(PC.css_record, CHARINDEX('<PostalCode>', PC.css_record) + 12 , 5 ) AS [State & ZipCode]
, **[Status] = CASE WHEN SIS.cs_id_number = PC.css_id THEN 'POSTED' ELSE 'Not Posted: Student may not be in PF Database yet or there might be a mismatch' end**
FROM
profile_convert PC
left JOIN say_im_stu SIS
ON SIS.cs_id_number = PC.css_id
order by css_id
End
答案 0 :(得分:2)
根据您的说明,您可以尝试添加与此类似的WHERE
子句:
...
where (@Status = 'All' -- All rows regardless of status
or (@Status = 'Posted' and SIS.cs_id_number = PC.css_id)
or (@Status = 'Not Posted' and (SIS.cs_id_number <> PC.css_id or SIS.cs_id_number is null)))
我假设您将参数@Status
传递给报告,该报告可以是以下值之一: