Dmana
Dmana

Reputation: 35

Subquery returned more than 1 value. This is not permitted when the subquery follows ... or when the subquery is used as an expression

I know subquery return more than 1 value but I don't know how to change the code. Can anyone help me ?

declare @sProjectNumber nvarchar(200)

( select Project from Project_Table where  Project in (
            select case 
            when @sProject is null then (select distinct Project from Project_Table)
            else @sProject end
from Project_Table)
)

Upvotes: 0

Views: 46

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269933

I am guessing that you really intend something like this:

select Project
from Project_Table
where @sProject is NULL or Project = @sProject;

This will return the project in @sProject or all projects if that value is NULL.

Upvotes: 1

Related Questions