0

我正在提取医院每日患者的报告。Mypatient_ref_master包含新老患者。我已将 2 列视为新的、旧的。我想以这样一种方式获取报告,即当患者年龄较大时,患者 ID 应位于旧列下,否则患者 ID 应位于新列下。我将存储过程的结果绑定到报告。当我将我的 SP 的结果绑定到使用 C# 代码中的数据进行操作的网格时,它工作正常。但是当我尝试使用 .RDLC 报告时,我也会在旧列和新列中获得所有患者 ID。我可以在我的存储过程本身中使用 switch case 来过滤掉它吗?以下是我的存储过程。

ALTER PROCEDURE [dbo].[Daily_Report] '2013/08/02'
    -- Add the parameters for the stored procedure here
        -- Add the parameters for the stored procedure here
(
      @date varchar(20)
)
AS
BEGIN
    SET NOCOUNT ON;
    SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
SELECT  
    convert(varchar,Patient_Ref_master.creation_Date,105) as 'creation_Date',        
    Patient_Ref_master.Sr_No as 'sr_No',
    old_new_patient.old_new as 'old_new',
    Patient_Ref_master.Pat_ID as 'Pat_ID',
    Patient_Master.Pat_FName +' '+Patient_Master.Pat_SName as 'NAME',

    Dept_ID as 'Dept_ID',
    Dept_Master.Dept_Name as 'Dept_Name',
    Doc_Master.Doc_ID as 'Doc_Master',
    Doc_Master.Doc_FName+' '+Doc_Master.Doc_SName as 'Doc_Name',
    Patient_Master.Pat_Addr as 'addr',
    Gender_master.Name1 as 'Pat_Sex',
    Patient_Master.Age as 'age'


    FROM Patient_Ref_master             
    left join dbo.old_new_patient on dbo.old_new_patient.code=Patient_Ref_master.old_new   
    left join dbo.Dept_Master  on   Dept_Master.Dept_code  =   Patient_Ref_master.Dept_ID
    left join Patient_Master on Patient_Master.Pat_Code=Patient_Ref_master.Pat_ID 
    left join Doc_Master on Doc_Master.Doc_ID=Patient_Ref_master.Doc_ID 
    left join Gender_master on Gender_master.Code=Patient_Master.Pat_Sex
 where         
 Patient_Ref_master.creation_Date=@date
--MONTH(Patient_Ref_master.creation_Date)=@month and Dept_ID=@dept

    order by Patient_Ref_master.Sr_No asc


I want something like the following. where 1st row has the patient for 2nd aug under Patient_ID_New column because he is new and 2nd line because he is old. I want a blank space like 1st row in Patient_Id_Old coumn


  Date          No  Patient_ID_New  Patient ID Old
  02-08-2013    11  11                            
  02-08-2013    13                           1
4

2 回答 2

3

是的,您可以将 case statemnet 用于以下用途:

 Select 
      (Case when "condition for oldpatient" Then PatientName Else Null End) Old_Patient,
      (Case when "condition for Newpatient" Then PatientName Else Null End) New_Patient
 From TableName
于 2013-08-02T20:12:06.520 回答
0

啊,现在我明白了。我想这就是你想要的...

SELECT  
    convert(varchar,Patient_Ref_master.creation_Date,105) as 'creation_Date',        
    Patient_Ref_master.Sr_No as 'sr_No',
    Case When old_new_patient.old_new = 0x1 Then old_new_patient.old_new
        Else Patient_Ref_master.Pat_ID
    End as 'Pat_ID',
    Patient_Master.Pat_FName +' '+Patient_Master.Pat_SName as 'NAME',
于 2013-08-02T20:19:04.440 回答