对于 MS SQL SERVER 中的每个? [英] for each in MS SQL SERVER?
本文介绍了对于 MS SQL SERVER 中的每个?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两张桌子:
Employees(EmployeeID, EmployeeName, EmployeeStatus, BasicSalary)
和
EmployeePayroll (PayrollID, EmployeeID, VoucherNo, BasicSalary, SalaryMonth)
我想为第一个表中的每个员工创建一个 for each
循环,以便我可以插入虚拟数据,例如 (0, EmployeeID,0 ,0 ,0)
进入第二个表.
I want to make a for each
loop for every employee in the first table so that I can insert dummy data like (0, EmployeeID,0 ,0 ,0)
into the second table.
我尝试使用 for
循环来实现,但我无法实现,那么 MS SQL Server 中是否有 for each
循环??
I tried to make it with a for
loop but I could not make it, so is there a for each
loop in MS SQL Server??
推荐答案
使用以下语句:
INSERT INTO EmployeePayroll
SELECT
0,EmployeeID ,0,0,0
FROM
Employees
您可以在插入之前通过附加来检查记录是否存在:
You can check for the existance of the record before inserting it by appending:
WHERE
ID NOT IN
(
SELECT
EmployeeID
FROM
EmployeePayroll
)
这篇关于对于 MS SQL SERVER 中的每个?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文