我有这段代码,我知道这不是完成这项工作的最有效方法,但我能说什么!我是 SQL 新手,我一行一行地做所有事情。基本上我正在更新表中的特定字段。我需要找到总更新,因为你看到列表太长而且我还有更多,所以我知道需要知道我有多少总更新。有谁知道我是否可以在 SQL 中做到这一点,而不仅仅是将代码复制并粘贴到 word 文档中并计算单词Update的数量。临时表可以做这样的事情吗?
UPDATE tblMEP_MonthlyData
SET Consumption = 51634
FROM tblMEP_Sites
JOIN tblMEP_Meters
ON tblMEP_Meters.SiteID = tblMEP_Sites.ID
JOIN tblMEP_Monthlydata
ON tblMEP_MonthlyData.MeterID = tblMEP_Meters.ID
WHERE ProjectID = 40
AND Consumption != 51634
AND tblMEP_Sites.Name LIKE '%Altgeld%'
AND Type = 1
AND BillingMonth = '2012-11-01 00:00:00.000'
-----------------------------------------------------------------------------
UPDATE tblMEP_MonthlyData
SET Consumption = 38370
FROM tblMEP_Sites
JOIN tblMEP_Meters
ON tblMEP_Meters.SiteID = tblMEP_Sites.ID
JOIN tblMEP_Monthlydata
ON tblMEP_MonthlyData.MeterID = tblMEP_Meters.ID
WHERE ProjectID = 40
AND tblMEP_Sites.Name LIKE '%Altgeld%'
AND Consumption != 38370
AND Type = 1
AND BillingMonth = '2012-10-01 00:00:00.000'
-----------------------------------------------------------------------------
UPDATE tblMEP_MonthlyData
SET Consumption = 108610
FROM tblMEP_Sites
JOIN tblMEP_Meters
ON tblMEP_Meters.SiteID = tblMEP_Sites.ID
JOIN tblMEP_Monthlydata
ON tblMEP_MonthlyData.MeterID = tblMEP_Meters.ID
WHERE ProjectID = 40
AND tblMEP_Sites.Name LIKE '%Avond%'
AND Consumption != 108610
AND Type = 1
AND BillingMonth = '2012-8-01 00:00:00.000'
-----------------------------------------------------------------------------
UPDATE tblMEP_MonthlyData
SET Consumption = 107923
FROM tblMEP_Sites
JOIN tblMEP_Meters
ON tblMEP_Meters.SiteID = tblMEP_Sites.ID
JOIN tblMEP_Monthlydata
ON tblMEP_MonthlyData.MeterID = tblMEP_Meters.ID
WHERE ProjectID = 40
AND tblMEP_Sites.Name LIKE '%Avond%'
AND Consumption != 107923
AND Type = 1
AND BillingMonth = '2012-9-01 00:00:00.000'
---------------------------------------------------------------------------------
UPDATE tblMEP_MonthlyData
SET Consumption = 1442
FROM tblMEP_Sites
JOIN tblMEP_Meters
ON tblMEP_Meters.SiteID = tblMEP_Sites.ID
JOIN tblMEP_Monthlydata
ON tblMEP_MonthlyData.MeterID = tblMEP_Meters.ID
WHERE ProjectID = 40
AND tblMEP_Sites.Name LIKE '%Belmont-cragin Pre-k%'
AND Consumption != 1442
AND Type = 1
AND BillingMonth = '2012-7-01 00:00:00.000'
-----------------------------------------------------------------------------
UPDATE tblMEP_MonthlyData
SET Consumption = 1477
FROM tblMEP_Sites
JOIN tblMEP_Meters
ON tblMEP_Meters.SiteID = tblMEP_Sites.ID
JOIN tblMEP_Monthlydata
ON tblMEP_MonthlyData.MeterID = tblMEP_Meters.ID
WHERE ProjectID = 40
AND tblMEP_Sites.Name LIKE '%Belmont%'
AND Consumption != 1477
AND Type = 1
AND BillingMonth = '2012-8-01 00:00:00.000'
-----------------------------------------------------------------------------
UPDATE tblMEP_MonthlyData
SET Consumption = 1636
FROM tblMEP_Sites
JOIN tblMEP_Meters
ON tblMEP_Meters.SiteID = tblMEP_Sites.ID
JOIN tblMEP_Monthlydata
ON tblMEP_MonthlyData.MeterID = tblMEP_Meters.ID
WHERE ProjectID = 40
AND tblMEP_Sites.Name LIKE '%Belmont%'
AND Consumption != 1636
AND Type = 1
AND BillingMonth = '2012-9-01 00:00:00.000'
-----------------------------------------------------------------------------
UPDATE tblMEP_MonthlyData
SET Consumption = 1451
FROM tblMEP_Sites
JOIN tblMEP_Meters
ON tblMEP_Meters.SiteID = tblMEP_Sites.ID
JOIN tblMEP_Monthlydata
ON tblMEP_MonthlyData.MeterID = tblMEP_Meters.ID
WHERE ProjectID = 40
AND tblMEP_Sites.Name LIKE '%Belmont%'
AND Consumption != 1451
AND Type = 1
AND BillingMonth = '2012-10-01 00:00:00.000'
-----------------------------------------------------------------------------
UPDATE tblMEP_MonthlyData
SET Consumption = 1615
FROM tblMEP_Sites
JOIN tblMEP_Meters
ON tblMEP_Meters.SiteID = tblMEP_Sites.ID
JOIN tblMEP_Monthlydata
ON tblMEP_MonthlyData.MeterID = tblMEP_Meters.ID
WHERE ProjectID = 40
AND tblMEP_Sites.Name LIKE '%Belmont%'
AND Consumption != 1615
AND Type = 1
AND BillingMonth = '2012-11-01 00:00:00.000'