嗯-您肯定需要对数据集进行一些程序调整,以将该组日期添加到详细信息行。我不确定您将如何导入 xlsx,但我建议首先使用 SSIS 包,然后在脚本任务中进行调整,这是执行此操作的“最佳”方式。请参阅here,了解如何在 SSIS 脚本任务中处理 Excel。
如果您不了解 SSIS 或特别是编程,那么您最好的选择(在我看来)是将数据导入临时表,使用 T-SQL 进行操作,然后将该表插入你的主桌。我做了这个here的SQL Fiddle。
CREATE TABLE ActivitySummary
(
id int identity(1,1),
activity_date date,
activity varchar(100),
paid_time decimal(5,2),
unpaid_time decimal(5,2),
total_time decimal(5,2)
)
CREATE TABLE ActivitySummary_STG
(
id int identity(1,1),
activity_date date,
activity varchar(100),
paid_time decimal(5,2),
unpaid_time decimal(5,2),
total_time decimal(5,2)
)
GO
-- Simulate import of Excel sheet into staging table
truncate table ActivitySummary_STG;
GO
INSERT INTO ActivitySummary_STG (activity_date, activity, paid_time, unpaid_time, total_time)
select '8/14/17',null,null,null,null
UNION ALL
select null,'001 Lunch',0,4.4,4.4
UNION ALL
select null,'002 Break',4.2,0,4.2
UNION ALL
select null,'007 System Down',7.45,0,7.45
UNION ALL
select null,'019 End of Work Day',0.02,0,0.02
UNION ALL
select '8/15/17',null,null,null,null
UNION ALL
select null,'001 Lunch',0,4.45,4.45
UNION ALL
select null,'002 Break',6.53,0,6.53
UNION ALL
select null,'007 System Down',0.51,0,0.51
UNION ALL
select null,'019 End of Work Day',0.02,0,0.02
GO
-- Code to massage data
declare @table_count int = (select COALESCE(count(id),0) from ActivitySummary_STG);
declare @counter int = 1;
declare @activity_date date,
@current_date date;
WHILE (@table_count > 0 AND @counter <= @table_count)
BEGIN
select @activity_date = activity_date
from ActivitySummary_STG
where id = @counter;
if (@activity_date is not null)
BEGIN
set @current_date = @activity_date;
delete from ActivitySummary_STG
where id = @counter;
END
else
BEGIN
update ActivitySummary_STG SET
activity_date = @current_date
where id = @counter;
END
set @counter += 1;
END
INSERT INTO ActivitySummary (activity_date, activity, paid_time, unpaid_time, total_time)
select activity_date, activity, paid_time, unpaid_time, total_time
from ActivitySummary_STG;
truncate table ActivitySummary_STG;
GO
select * from ActivitySummary;