SoftwareNerd SoftwareNerd - 2 months ago 7
ASP.NET (C#) Question

Bind to grid by selecting data from tow different tables?

I have two tables in my database named...Requests and Balance tracker which has no relation....but i want to select data from two tables and binf it two grid...

Requests

EmpID |EmpRqsts|EmpDescription|ApproverID
1 |asdfsb |sadbfsbdf |1
2 |asbfd |sjkfbsd |1


Balance Tracker

EmpId|BalanceAmnt|LastUpdated
| 1 |5000 |sdfbk
| 2 |3000 |sjbfsh


Employee Table

EmpId|EmpName
1 |Anil
2 |Raghu


Now Balance tracker has ForeignKey column of EmployeeTable... What I want is to select [EmpName ] from EmpTable [EmpRqsts] from [Requests] and [BalanceAmnt][LastUpdated] from [Balance Tracker] and bind it to grid

This is my stored procedure I am using to retrieve the data

create procedure SP_GetEmployeeRequests
(@ApproverName varchar (50))
as
begin
select
EmployeeDetails.Emp_Username,
RequestDetails.Request_Amount,
RequestDetails.Request_description,
BalanceTracker.Balance_Amount,
BalanceTracker.LastApproval,
BalanceTracker.LastUdated
from
EmployeeDetails, RequestDetails, BalanceTracker
where
EmployeeDetails.Emp_ID = RequestDetails.Emp_ID
and BalanceTracker.Emp_ID = RequestDetails.Emp_ID
and RequestDetails.Approved_ID = (select Approved_ID
from ApprovalDetails
where Approved_By = @ApproverName)
end


Everything is fine till here but this query is retrieving only the column names. But not the values of the tables..can any one help me whats wrong in my query..

Answer

I solved my answer thanks for evere one who tried to help me....i am posting my answer,so that it can be help full to any one in need...

 CREATE procedure SP_GetEmployeeRequests
(
     @ApproverName varchar (50)
)
AS
BEGIN

SELECT PTS_Employee.Emp_Username, PTS_Requests.Request_RequestedAmount, PTS_Requests.Request_Description, PTS_BalanceTracker.Balance_BalanceAmount, PTS_BalanceTracker.Balance_LastApproval, PTS_BalanceTracker.Balance_LastUpdated
FROM PTS_Employee  JOIN PTS_Requests  ON PTS_Employee.Emp_ID = PTS_Requests.Emp_ID 
JOIN PTS_BalanceTracker  ON PTS_BalanceTracker.Emp_ID = PTS_Requests.Emp_ID
JOIN PTS_Approval  ON PTS_Approval.Approval_ApprovedID  = PTS_Requests.Approval_ApprovedID
WHERE PTS_Approval.Approval_ApprovedBY = @ApproverName 

END
GO