Sql 获取受insert语句影响的详细行数

Sql 获取受insert语句影响的详细行数,sql,database-partitioning,rows-affected,Sql,Database Partitioning,Rows Affected,“我的表”是使用名为“月”的列之一设置的。 我在表上运行SQLINSERT语句,并获得受影响的行数 是否有办法获得每个“月”值受影响的行数 如果我的表在“Month”列上是分区,这有帮助吗 我的sql是如下所示的标准sql: 插入到“TargetTable”中 (第1栏、第2栏、月份、第4栏……) 选择列名称 来自SourceTable 我正在使用.Net的SqlClient中的SqlCommand将sql传递到sql server中。单个insert语句返回单个受影响的行数。您对每个“月”值执

“我的表”是使用名为“月”的列之一设置的。 我在表上运行SQLINSERT语句,并获得受影响的行数

是否有办法获得每个“月”值受影响的行数

如果我的表在“Month”列上是分区,这有帮助吗

我的sql是如下所示的标准sql:

插入到“TargetTable”中 (第1栏、第2栏、月份、第4栏……) 选择列名称 来自SourceTable


我正在使用.Net的SqlClient中的SqlCommand将sql传递到sql server中。

单个
insert
语句返回单个受影响的行数。您对每个“月”值执行单独的insert,因此12个insert语句而不是1个。这将对性能产生一些影响

或者,您可以将要插入的行加载到临时表中,然后执行插入操作,然后报告相关内容,大致如下所示:

create table #work
( month                     int not null ,
  primary_key_of_real_table int not null ,
)
insert #work
select t.month , t.primary_key_column
from source_table t
where -- your filter criteria here

insert target_table
( ... column list ... )
select ... column list ...
from #work t
join source_table x on x.primary_key_column =t.primary_key_of_real_table

select m.month , cnt = sum(case when t.month is null then 1 else 0 end)
from ( select month = 1 union all
       select month = 2 union all
       ...
       select month = 12
     ) m
left join #work t on t.month = m.month
group by t.month
order by t.month

请包含您的sql。谢谢。出于性能原因,我对insert语句进行了分组,因此出于同样的考虑,无法使用此选项。