自动插入数据

发布于 2024-08-18 14:45:11 字数 285 浏览 4 评论 0原文

我有一个名为“加班时间”的表,其中包含以下列 Ot_ID、轮班日期、员工 ID、工作时间。

我需要做的是在每个月的第一天自动在这些表中插入一组值。

例如,我需要添加一月的值('1/1/2010',12345,4.6), value('2/1/2010',12345,4.6) 为二月,依此类推全年。

必须进行此添加,以便仅包含特定的员工列表,并且每个月的工时值都是恒定的。 我正在后端使用 MS SQL Server 2000。和 Visual Studio,前端为 C Sharp 的 Winforms。

I have a table name Overtime Hours which have the following columns
Ot_ID, Shift_Date, Employee_ID, Hours.

What I need to do is insert a set of values in these tables on the 1st date of every month, automatically.

for example, I need to add values('1/1/2010',12345,4.6) for january,
values('2/1/2010',12345,4.6) for february and so on for the whole year.

This addition has to be done so a certain list of employees only and the Hours value is constant for every month.
I am working on MS SQL Server 2000 in the backend. and visual studio, Winforms on C sharp in the front end.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

白首有我共你 2024-08-25 14:45:11

SQL Server代理服务可以安排您每月执行的工作(插入新记录);这完全可以在MSSQL2000内完成,不需要任何前端编程。

The SQL Server Agent Service can schedule your job (of inserting new records) to be carried out every month; this can be done entirely within MSSQL2000 and doesn't need any front-end programming.

薔薇婲 2024-08-25 14:45:11

您可以使用公用表表达式创建月份列表。使用交叉联接为每个月的每个员工生成一行,并将其插入到小时表中。

一些带有表变量的示例代码:

declare @hourtable table (
    ot_id int identity(1,1),
    shift_date datetime,
    employee_id int,
    hours float)

declare @employees table (
    employee_id int
)   

insert into @employees select 1
insert into @employees select 2

;with months as (
    select cast('2009-01-01' as datetime) as month
    union all
    select dateadd(m,1,month)
    from months
    where month < '2009-12-01'  
)
insert into @hourtable
(shift_date, employee_id, hours)
select m.month, e.employee_id, 1.23
from months m
cross join @employees e

select * from @hourtable

You can create a list of months using a common table expression. Use cross join to generate a row for each employee for each month, and insert that into the hours table.

Some example code, with table variables:

declare @hourtable table (
    ot_id int identity(1,1),
    shift_date datetime,
    employee_id int,
    hours float)

declare @employees table (
    employee_id int
)   

insert into @employees select 1
insert into @employees select 2

;with months as (
    select cast('2009-01-01' as datetime) as month
    union all
    select dateadd(m,1,month)
    from months
    where month < '2009-12-01'  
)
insert into @hourtable
(shift_date, employee_id, hours)
select m.month, e.employee_id, 1.23
from months m
cross join @employees e

select * from @hourtable
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文