在SQL Server中的子查询中调用存储过程的语法是什么?

时间:2018-06-12 11:13:15

标签: sql-server tsql stored-procedures subquery

我已经为子查询中的连接编写了一个存储过程,问题是我没有在子查询中调用存储过程的语法

SELECT 
    t33.value AS Area, t33.value2 AS AreaBlock, 
    t33.value3 AS FarmId, t33.StartTime AS startTime, 
    t33.WindSpeed, t33.Direction AS WindDirection,
    t33.Note AS note, t33.ChemicalApplicationID, 
    t33.StartDate, t33.TreatmentType, t33.Model AS EquipmentModel, 
    t33.TankSize, t33.TaskNumber, t33.FinishTime, t33.FirstName, 
    t33.value4 AS totalLand, t33.value5 AS areaUnit, 
    t33.value6 AS totalLandByArea, t33.value7 AS areaUnitByArea
FROM 
    (SELECT 
         ROW_NUMBER() OVER (ORDER BY t32.StartDate DESC) AS ROW_NUMBER, 
         t32.value, t32.value2, t32.value3, t32.StartTime, t32.WindSpeed,
         t32.Direction, t32.Note, t32.ChemicalApplicationID, t32.StartDate, 
         t32.TreatmentType, t32.Model, t32.TankSize, t32.TaskNumber,
         t32.FinishTime, t32.FirstName, t32.value4, t32.value5, t32.value6, 
         t32.value7
     FROM 
         (SELECT 
              (SELECT t9.Name 
               FROM 
                   (SELECT TOP (1) t7.Name
                    FROM ChemicalApplicationLand AS t4
                    INNER JOIN Zone AS t5 ON t4.LandID = t5.LandID
                    INNER JOIN Block AS t6 ON t5.ZoneID = t6.ZoneID
                    INNER JOIN Farm AS t7 ON t7.FarmID = t5.FarmID
                    INNER JOIN Land AS t8 ON t8.LandID = t6.LandID
                     WHERE t4.ChemicalApplicationID = t0.ChemicalApplicationID) AS t9) AS value, 
              (SELECT *
               FROM 
                   (SELECT TOP (1) t13.Name
                    FROM ChemicalApplicationLand AS t10
                    INNER JOIN Block AS t11 ON t10.LandID = t11.LandID
                    INNER JOIN Zone AS t12 ON t12.ZoneID = t11.ZoneID
                    INNER JOIN Farm AS t13 ON t13.FarmID = t12.FarmID
                    INNER JOIN Land AS t14 ON t14.LandID = t11.LandID
                    WHERE t10.ChemicalApplicationID = (t0.ChemicalApplicationID)) AS t15) AS value2, 
              (SELECT TOP (1) t17.FarmID
               FROM Land AS t16, Farm AS t17
               WHERE (t16.LandID = t0.LandID) AND (t17.LandID = t16.LandID)) AS value3, 
              (SELECT SUM(t19.LandArea)
               FROM ChemicalApplicationLand AS t18
               INNER JOIN Land AS t19 ON t18.LandID = (t19.LandID)
               WHERE (t18.ChemicalApplicationID = (t0.ChemicalApplicationID)) 
                 AND (t19.LandArea IS NOT NULL)) AS value4,  
             (SELECT TOP (1) t21.Unit
              FROM ChemicalApplicationLand AS t20
              INNER JOIN Land AS t21 ON t20.LandID = (t21.LandID)
              WHERE (t20.ChemicalApplicationID = (t0.ChemicalApplicationID)) 
                AND (t21.LandArea IS NOT NULL)) AS value5, 
             (SELECT SUM(t26.LandArea)
              FROM ChemicalApplicationLand AS t22
              INNER JOIN Zone AS t23 ON t22.LandID = (t23.LandID)
              INNER JOIN Block AS t24 ON t23.ZoneID = t24.ZoneID
              INNER JOIN Farm AS t25 ON t25.FarmID = t23.FarmID
              INNER JOIN Land AS t26 ON t26.LandID = t24.LandID
              WHERE t22.ChemicalApplicationID = (t0.ChemicalApplicationID)) AS value6, 
             (SELECT TOP (1) t31.Unit
              FROM ChemicalApplicationLand AS t27
              INNER JOIN Zone AS t28 ON t27.LandID = (t28.LandID)
              INNER JOIN Block AS t29 ON t28.ZoneID = t29.ZoneID
              INNER JOIN Farm AS t30 ON t30.FarmID = t28.FarmID
              INNER JOIN Land AS t31 ON t31.LandID = t29.LandID
              WHERE t27.ChemicalApplicationID = (t0.ChemicalApplicationID)) AS value7, 
             t0.CompanyID, t0.StartTime, t0.WindSpeed, t0.Direction, 
             t0.Note, t0.ChemicalApplicationID, t0.StartDate, 
             t0.TreatmentType, t3.Model, t0.TankSize, t0.TaskNumber, 
             t0.FinishTime, t2.FirstName
         FROM 
             ChemicalApplication AS t0
         LEFT OUTER JOIN 
             Member AS t1 ON t1.MemberID = t0.OperatedBy
         INNER JOIN 
             Member AS t2 ON t0.OperatedBy = (t2.MemberID)
         LEFT OUTER JOIN 
             Equipment AS t3 ON t3.EquipmentID = t0.EquipmentID) AS t32
     WHERE 
         (t32.ChemicalApplicationID > 0) AND (t32.CompanyID = 1000000139)) AS t33
WHERE 
    t33.ROW_NUMBER BETWEEN 0 + 1 AND 0 + 25
ORDER BY 
    t33.ROW_NUMBER    

0 个答案:

没有答案