Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL 2000 Using "Case" statement with "in" clause 1

Status
Not open for further replies.

RileyCat

Programmer
Apr 5, 2004
124
US
I'm trying to write a "case" statement with the "in" clause and am getting compile errors.

So here's my code . . .

Code:
where . . .
      IdCapPlusSrc in
	case
		when @Status = 4004 then
			(select distinct IdCapPlusSrc
			 from   CapPlus with (nolock)
			 where	TmsSent is NULL)
		else (select IdCapPlusSrc
                      from   CapPlusSrc with (nolock)
                      where  Status = @Status)
		end

The errors I'm getting on compile . . .

Code:
Incorrect syntax near the keyword 'case'.
Incorrect syntax near the keyword 'else'.

So is the "in" clause not allowed with a "case" statement, or do I have some bad syntax?

Any help is appreciated.

Thanks!

Stay Cool Ya'll! [smile2]

-- Kristin
 
Code:
where . . .
     ((@Status = 4004 AND  
       IdCapPlusSrc in (select distinct IdCapPlusSrc
                               from   CapPlus with (nolock)
                        where    TmsSent is NULL)) OR
      (@Status <> 4004 AND  
       IdCapPlusSrc in (select IdCapPlusSrc
                               from   CapPlusSrc with (nolock)
                        where  Status = @Status)))

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top