如何从数据库中选择特定数据并在网格中显示

如何从数据库中选择特定数据并在网格中显示

问题描述:

DROP PROCEDURE IF EXISTS hms.Select_Parameter1;
CREATE PROCEDURE hms.`Select_Parameter1`(_Branch_Id     int,
                                         _Tenant_Id     int,
                                         _disease_Id    int,_ParameterId int)
BEGIN
      IF EXISTS
            (SELECT  b.Target_Value
               FROM patient_progress_tracking_header b
              WHERE b.DiseaseId = _disease_Id)
      THEN
         SELECT a.ParameterName,
                b.Target_Value,
                b.Measurement_Frequency,
                date_format(c.Last_Date,"%y/%d/%m") as 'Last_Date',
                c.Result,
                 date_format(c.Next_Due_Date,"%y/%d/%m") as 'Next_Due_Date',
                c.Remarks,
                date_format(c.Current_Test_Date,"%y/%d/%m") as 'Current_Test_Date',
                b.ParameterId 
                
           FROM patient_progress_tracking_header b
                RIGHT JOIN Disease_parameter a
                   ON a.ParameterId = b.ParameterId
                INNER JOIN patient_progress_tracking_details c
                   ON b.ParameterId = c.ParameterId
          WHERE     b.Branch_Id = _Branch_Id
                AND b.Tenant_Id = _Tenant_Id
                AND b.DiseaseId = _disease_Id;
      ELSE
         SELECT a.ParameterName,
                a.Target_Value,
                b.Measurement_Frequency,
                date_format(c.Last_Date,"%y/%d/%m") as 'Last_Date',
                c.Result,
                 date_format(c.Next_Due_Date,"%y/%d/%m") as 'Next_Due_Date',
                c.Remarks,
                date_format(c.Current_Test_Date,"%y/%d/%m") as 'Current_Test_Date',
                a.ParameterId
                
           FROM patient_progress_tracking_header b
                RIGHT JOIN Disease_parameter a
                   ON  b.ParameterId =a.ParameterId
                INNER JOIN patient_progress_tracking_header b
                   ON b.ParameterId = c.ParameterId
          WHERE     a.Branch_Id = _Branch_Id
                AND a.Tenant_Id = _Tenant_Id
                AND a.DiseaseId = _disease_Id
                AND a.ParameterId=_ParameterId;
      END IF;
   END;



这是我的sp。问题是其他部分没有执行...因为 ON b.ParameterId = c.ParameterId 表中没有这个条件..我希望当patient_progress_tracking_header中没有数据时b table和patient_progress_tracking_header b表,目标值和参数名称应来自Disease_parameter并显示在grid ..


this is my sp. Problem is else part is not executing ...because ON b.ParameterId = c.ParameterId this condition is not present in table..i want when there is no data in patient_progress_tracking_header b table and patient_progress_tracking_header b table ,Target value and parameter name should come from Disease_parameter and displayed in grid..





在你的else部分查询,其中是别名表C,c未声明。



Hi,

In your else part query where is alias table C, c is not declared.

SELECT a.ParameterName,
                a.Target_Value,
                b.Measurement_Frequency,
                date_format(c.Last_Date,"%y/%d/%m") as 'Last_Date',
                c.Result,
                 date_format(c.Next_Due_Date,"%y/%d/%m") as 'Next_Due_Date',
                c.Remarks,
                date_format(c.Current_Test_Date,"%y/%d/%m") as 'Current_Test_Date',
                a.ParameterId
                
           FROM patient_progress_tracking_header b
                RIGHT JOIN Disease_parameter a
                   ON  b.ParameterId =a.ParameterId
                INNER JOIN patient_progress_tracking_header b
                   ON b.ParameterId = c.ParameterId
          WHERE     a.Branch_Id = _Branch_Id
                AND a.Tenant_Id = _Tenant_Id
                AND a.DiseaseId = _disease_Id
                AND a.ParameterId=_ParameterId;