Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Nested Select statement problem

Author  Topic 

empyrean
Starting Member

14 Posts

Posted - 2009-12-25 : 23:26:27
hi i wanted to insert select statement inside select inside select. is it possible to do this? i am having problem with the following query. please help me..

ALTER PROCEDURE [test]
@Leader_ID nvarchar(255)
-- Add the parameters for the stored procedure here
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
SELECT a.Leader_ID , a.Employee_ID, e.EmployeeName,
(SELECT b.EmpProj_RWS (Select c.Subproj_Description from SubProj_Table c where c.Subproj_ID = d.SubprojID)
FROM EmployeeProject_Table b
where a.Employee_ID = b.Employee_ID)
AS Emp_RWS from LeaderEmployee_Table a, Employee_Table e, SubprojYear_Table d
where Leader_ID = @Leader_ID and e.Employee_ID = a.Employee_ID and d.SubprojYear_ID = b.SubprojYear_ID

END

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-26 : 00:14:59
Your query doesn't make sense. Rather than trying to get that to work, why don't you instead show us some sample data for your tables and the expected result set using that sample data? We'll then be able to come up with a solution for you. You probably don't need those subqueries and can instead just use joins.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-12-26 : 00:21:42
is this u want

SELECT a.Leader_ID , a.Employee_ID, e.EmployeeName,b.EmpProj_RWS,c.Subproj_Description
FROM LeaderEmployee_Table a
INNER JOIN Employee_Table e ON e.Employee_ID = a.Employee_ID
LEFT JOIN EmployeeProject_Table b ON a.Employee_ID = b.Employee_ID
LEFT JOIN SubprojYear_Table d ON d.SubprojYear_ID = b.SubprojYear_ID
LEFT JOIN SubProj_Table c ON c.Subproj_ID = d.SubprojID
WHERE Leader_ID = @Leader_ID
Go to Top of Page
   

- Advertisement -