SQL Server Temp table to update Fields -
i have code, when run following:
declare @consumption float = 2211, @billingmonth datetime = '2012-11-01 00:00:00.000', @sitename varchar(100) = 'aldr', @type int = 1 select consumption, meterid, siteid tblmep_sites join tblmep_meters on tblmep_meters.siteid = tblmep_sites.id join tblmep_monthlydata on tblmep_monthlydata.meterid = tblmep_meters.id projectid = 40 , tblmep_sites.name @sitename , type = @type , billingmonth = @billingmonth
result:
consumption meterid siteid 25900 13274 1622
i want update consumption field using the update statement:
update tblmep_monthlydata set consumption= @consumption
and meterid , siteid result following:
consumption meterid siteid 2211 13274 1622
is temptables solution problem? if yes, how convert above code temp tables?
you want first update
, select
of data.
update md set consumption = @consumption tblmep_sites s inner join tblmep_meters m on m.siteid = s.id inner join tblmep_monthlydata md on md.meterid = m.id projectid = 40 -- use table alias prefix , s.name @sitename -- changed "=" because -- doing same , type = @type -- use table alias prefix , billingmonth = @billingmonth -- use table alias prefix select consumption, meterid, siteid tblmep_sites s inner join tblmep_meters m on m.siteid = s.id inner join tblmep_monthlydata md on md.meterid = m.id projectid = 40 , s.name @sitename , type = @type , billingmonth = @billingmonth
Comments
Post a Comment