SQL Server Calculate the total update -
i have code, know not efficient way job done can say! new sql , line line. updating specific fields in table. need find total update, see list long , have more know need know how many total updates have. know if can in sql other copying , pasting code word document , count number of word update. can temp table that?
update tblmep_monthlydata set consumption = 51634 tblmep_sites join tblmep_meters on tblmep_meters.siteid = tblmep_sites.id join tblmep_monthlydata on tblmep_monthlydata.meterid = tblmep_meters.id projectid = 40 , consumption != 51634 , tblmep_sites.name '%altgeld%' , type = 1 , billingmonth = '2012-11-01 00:00:00.000' ----------------------------------------------------------------------------- update tblmep_monthlydata set consumption = 38370 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 '%altgeld%' , consumption != 38370 , type = 1 , billingmonth = '2012-10-01 00:00:00.000' ----------------------------------------------------------------------------- update tblmep_monthlydata set consumption = 108610 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 '%avond%' , consumption != 108610 , type = 1 , billingmonth = '2012-8-01 00:00:00.000' ----------------------------------------------------------------------------- update tblmep_monthlydata set consumption = 107923 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 '%avond%' , consumption != 107923 , type = 1 , billingmonth = '2012-9-01 00:00:00.000' --------------------------------------------------------------------------------- update tblmep_monthlydata set consumption = 1442 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 '%belmont-cragin pre-k%' , consumption != 1442 , type = 1 , billingmonth = '2012-7-01 00:00:00.000' ----------------------------------------------------------------------------- update tblmep_monthlydata set consumption = 1477 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 '%belmont%' , consumption != 1477 , type = 1 , billingmonth = '2012-8-01 00:00:00.000' ----------------------------------------------------------------------------- update tblmep_monthlydata set consumption = 1636 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 '%belmont%' , consumption != 1636 , type = 1 , billingmonth = '2012-9-01 00:00:00.000' ----------------------------------------------------------------------------- update tblmep_monthlydata set consumption = 1451 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 '%belmont%' , consumption != 1451 , type = 1 , billingmonth = '2012-10-01 00:00:00.000' ----------------------------------------------------------------------------- update tblmep_monthlydata set consumption = 1615 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 '%belmont%' , consumption != 1615 , type = 1 , billingmonth = '2012-11-01 00:00:00.000'
you may collect number of rows affected each statement using @@rowcount
variable. if store anywhere, may add following lines after each block of code:
set @rowsaffected=@@rowcount insert mytablewithtotals (rowsaffected) values (@rowsaffected)
of course should declare @rowsaffected
variable in beginning. using way able count number of rows , number of update statements well.
Comments
Post a Comment