从单个存储过程中获取两个表中的数据?

时间:2021-09-16 15:15:41

I have two tables, one is for task and one for all jobs. I am giving departmentid to sp and want to get all the jobid from task table and job table and return all detail of these jobs from jobid table. Please tell me if there is any solution.

我有两个表,一个用于任务,一个用于所有工作。我给了dismentid到sp并希望从任务表和作业表中获取所有jobid并从jobid表返回这些作业的所有细节。请告诉我是否有任何解决方案。

This is my task table:

这是我的任务表:

从单个存储过程中获取两个表中的数据?

This is my job table:

这是我的工作表:

从单个存储过程中获取两个表中的数据?

In task table the parameter departmentid goes to AssignedToDepartmentId. In JobId table the parameter depatmentid goes to DepartmentId.

在任务表中,参数departmentid转到AssignedToDepartmentId。在JobId表中,参数depatmentid转到DepartmentId。

First get all jobid from both tables by departmentid and then get details of all jobid and return detail of jobid.

首先通过departmentid从两个表中获取所有jobid,然后获取所有jobid的详细信息并返回jobid的详细信息。

these are my tasktable entries 从单个存储过程中获取两个表中的数据?

这些是我的任务表条目

these are my jobid table entries 从单个存储过程中获取两个表中的数据?

这些是我的jobid表条目

if I pass 7 as departmentid parameter then I should get all the columns of jobid table of two jobid "series" and Opportunity1005.

如果我将7作为departmentid参数传递,那么我应该获得两个jobid“series”和Opportunity1005的jobid表的所有列。

1 个解决方案

#1


0  

simple try this

简单试试这个

CREATE PROC p_GetTableData
@DepartmentId INT
AS 
BEGIN

    SELECT jt.* FROM Task_Table tt INNER JOIN JobId_Table jt ON tt.JobId  = jt.jobId
    WHERE tt.AssignByDepatmentId = @DepartmentId

END

#1


0  

simple try this

简单试试这个

CREATE PROC p_GetTableData
@DepartmentId INT
AS 
BEGIN

    SELECT jt.* FROM Task_Table tt INNER JOIN JobId_Table jt ON tt.JobId  = jt.jobId
    WHERE tt.AssignByDepatmentId = @DepartmentId

END