sql - SQL Server for loop assistance
问题描述
Ok so this is my stored proc so far.
ALTER Procedure GetJobInfo()
AS
BEGIN
Select EmployeeId, FirstName, LastName
From dbo.Employees
for EmployeeId
SELECT ComputerCodeId
From dbo.EmployeeJobs
Where ComputerCodeId = "F"
END
I need to get the employees which I have done, but then I need to get the employees jobs from the dbo.EmployeeJobs table that match an array of computer codes. How would I go about doing something like that? My end goal is to be able to create a report that breaks the employee jobs into two categories based on the computer code associated with them and then getting the sum of the two categories and having them populate two different columns.
解决方案
我不完全确定你想要什么,但你有这两个选择。
如果您的表 EmployeeJobs 包含 EmployeeId 列,请尝试使用此选项。
SELECT EJ.ComputerCodeId , E.EmployeeId, E.FirstName, E.LastName FROM dbo.EmployeeJobs As EJ INNER JOIN dbo.Employees As E ON EJ.EmployeeId = E.EmployeeId WHERE EJ.ComputerCodeId = 'F'
否则,如果您无法匹配 EmployeeId,您可以使用以下内容,这将按 ComputerCodeId 过滤并由每个员工交叉。
SELECT EJ.ComputerCodeId , E.EmployeeId, E.FirstName, E.LastName
FROM dbo.EmployeeJobs As EJ, dbo.Employees As E
WHERE EJ.ComputerCodeId = 'F'
推荐阅读
- node.js - 无法使用 AWS EC2 实例上的端口 25 从 nodejs nodemailer 发送 gmail 地址的邮件
- docker - 对象引用未设置为行 app.UseDiscoveryClient() 处的对象实例;在 .NET Core API 的 Startup.cs 文件中
- java - Java Bank Account 类,用于跟踪特定时间范围内发生的交易
- python - 如何在可调用的 python 金字塔视图中进行依赖注入?
- nginx - Nginx phpMyAdmin 路由在 Windows 上不起作用
- javascript - 强制状态保持布尔值
- javascript - 所有代码在节点中运行时找不到节点:fs
- html - 为什么在 Visual Studio Code 中保存 .html 文件时会删除缩进
- python - 如何在并发运行的函数中一次执行部分代码?
- macos - Mac Sierra OS 上的 HTTPD 问题 - 无法在全新 brew 安装上启动