简体   繁体   English

如何使用存储过程从两个不同的表中获取数据?

[英]How to get data from two different tables using stored procedures?

I am new to functions so am having a bit starting trouble here 我是新手,所以这里有点麻烦

I have two tables like this 我有两张这样的桌子

Bugs 错误

BugID | Title | ProjectName | CreatedBy

BugHistory BugHistory

BughistoryID | BugID | Assignedto | ToStatus | FromStatus

EmployeeTable EmployeeTable中

EmployeeID | EmployeeName |

[AssignedTo] column from BugHistory is a foreign key for [EmployeeId] in EmployeeTable . [AssignedTo]从塔BugHistory为外键[EmployeeId]EmployeeTable

I want a select statement where I have to show the bugs table in gridview with [AssignedTo] and [Tostatus] columns from BugHistory table. 我想一个select语句,我必须展示在GridView控件与错误表[AssignedTo][Tostatus]从列BugHistory表。 How can I use functions for this both procedure s any ideas please? 我怎样才能使用这两个程序的功能呢?

In Assigned to column I want the name of the employee - how can I map this? Assigned to列中,我想要员工的姓名 - 我该如何映射?

It sounds like you want this: 听起来你想要这个:

SELECT b.BugId
    , b.Title
    , b.ProjectName
    , b.CreatedBy
    , e.EmployeeName As AssignedTo
    , bh.ToStatus
FROM Bugs b
INNER JOIN BugHistory bh
    ON b.bugid = bh.bugid
INNER JOIN Employee e
    ON bh.AssignedTo = e.EmployeeId

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何以两个表的形式从存储过程中获取数据? - How to get data from Stored Procedure in form of two tables? 如何在sql中查找用于不同数据库的存储过程中的表和视图? - How to find Tables and Views used in stored procedures of different database in sql? 如何合并两个存储过程 - How to merge two stored procedures 两个多线程 object 可以从数据库中调用两个不同的存储过程吗? - Can two multi-threaded object call two different stored procedures from a database? 如何从不同的表中获取两个日期的差异,并使用SQL查询将其生成为摘要? - How can I get the difference of two dates from different tables and generate it as a summary using SQL query? 无需使用存储过程即可从.net代码锁定和解锁sql server表 - lock and unlock sql server tables from .net code without using stored procedures 如何从SQL中两个表的不同列求和 - how to sum data from different columns of two tables in sql 使用多个存储过程将数据插入表中 - Insert data into table using multiple stored procedures 如何在同一实例中将表,函数和存储过程从一个数据库复制到另一个数据库 - How to copy tables , functions and stored procedures from one database to other in same Instance 从SP连接两个T-SQL存储过程的输出数据 - Joining output data of two T-SQL Stored Procedures from an SP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM