SoftwareNerd
SoftwareNerd

Reputation: 1895

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

BughistoryID | BugID | Assignedto | ToStatus | FromStatus

EmployeeTable

EmployeeID | EmployeeName |

[AssignedTo] column from BugHistory is a foreign key for [EmployeeId] in EmployeeTable.

I want a select statement where I have to show the bugs table in gridview with [AssignedTo] and [Tostatus] columns from BugHistory table. 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?

Upvotes: 0

Views: 2063

Answers (1)

Taryn
Taryn

Reputation: 247700

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

Upvotes: 2

Related Questions