-1

大家好,我有四个表,三个表有主键,第四个表有所有三个外键..现在我想写一个选择过程

my tables look like this

          usertable                                       RoleTable
  -----------------------                        ---------------------------
   UserID|UserName|userEmail|Pwd|RoleID                RoleID|RoleName
     1   |Anil    |akanil@gma|123|1                       1   |Admin


       Projecttable                                    WorkAssignedTable
-----------------------                       ---------------------------
ProjectID|ProName|                                  WorkID|userId|ProjectID|RoleID
     1   |Anil                                            |

现在我想为工作分配表编写一个选择存储过程,我必须从 sertbale 获取 [UserName],[UserMailId],从角色 tbale 获取 [rolename],从 Projecttable 获取 [ProjectName] 任何人都可以帮助如何编写存储过程为了这

4

2 回答 2

1

使用此查询

    Select U.UserName, R.RoleName,P.ProName from WorkAssignedTable WA 
inner join usertable U on WA.UserID = U.UserID
inner join RoleTable R on WA.RoleID = R.RoleID
inner join Projecttable P on WA.ProjectID = P.ProjectID

您可以使用左外连接(如果想要 WorkAssignedTable 的整个记录​​)

于 2012-07-17T10:56:12.800 回答
0

我最终这样做了:

    select  WorkAssigned.WorkID, usertable.EmployeeName, usertable.EmployeeEmailId,RoleTable.EmplopyeeRole,Projects.projectName,WorkAssigned.[Status] from WorkAssigned  
inner join EmployeeGroup  on RoleTable.GroupId=WorkAssigned.GroupId
inner join Projects  on Projects.ProjectId=WorkAssigned.ProjectId 
inner join EmployeeDetails on  usertable.EmployeId=WorkAssigned.EmployeId
于 2012-07-17T10:46:27.200 回答