我有这段代码,当我运行它时,我得到以下信息:
DECLARE @Consumption float = 2211,
@BillingMonth datetime = '2012-11-01 00:00:00.000',
@SiteName varchar(100) = 'Aldr',
@Type int = 1
SELECT Consumption, MeterID, SiteID
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 @SiteName
AND Type = @Type
AND BillingMonth = @BillingMonth
结果:
Consumption MeterID SiteID
25900 13274 1622
我想使用更新语句更新消费字段:
Update tblMEP_Monthlydata
SET Consumption= @Consumption
并且还获取 MeterID 和 SiteID,因此结果将如下所示:
Consumption MeterID SiteID
2211 13274 1622
tempTables 是解决这个问题的方法吗?如果是,我将如何将上述代码转换为临时表?