I have created a view in which I have inserted another select statement and labelled that statement as another fields with "alias"
The view got executed successfully but when trying to fire select statement from view (select * from view) it throws an error of
Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, <, <= , >, >= or when the subquery is used as an expression
Now I'm aware the reason of this error coming. It is because of that the inner select query returns more than 1 row. I cannot go for TOP 1 as I need to have more than one row.
ALTER VIEW [dbo].[TestView_new]
AS
SELECT TOP ( 100 ) PERCENT
dbo.DataRepository.PeriodStatus ,
dbo.DataRepository.TimesheetName ,
dbo.DataRepository.TimesheetLineClass ,
dbo.DataRepository.TimesheetLineClassUID ,
dbo.MSP_EpmResource_UserView.ResourceName ,
dbo.MSP_EpmProject_UserView.ProjectName AS ProjectName ,
( SELECT MSP_EpmProject_UserView.ProjectName
FROM dbo.MSP_EpmProject_UserView
LEFT JOIN dbo.DataRepository ON dbo.MSP_EpmProject_UserView.[ProjectUID] = dbo.DataRepository.[ProjectUID]
WHERE LTRIM(RTRIM(dbo.DataRepository.[ProjectUID])) IS NOT NULL
OR LTRIM(RTRIM(dbo.DataRepository.[ProjectUID])) <> '') AS ProjectName2 ,
FROM dbo.DataRepository
INNER JOIN dbo.MSP_TimesheetActual ON dbo.DataRepository.TimesheetLineUID = dbo.MSP_TimesheetActual.TimesheetLineUID
LEFT OUTER JOIN dbo.MSP_EpmResource_UserView ON dbo.DataRepository.ResourceUID = dbo.MSP_EpmResource_UserView.ResourceUID
LEFT OUTER JOIN dbo.MSP_EpmProject_UserView ON dbo.DataRepository.ProjectUID = dbo.MSP_EpmProject_UserView.ProjectUID
My Question: Is there any way that the error can be resolved?