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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use of Case in the where clause

Status
Not open for further replies.

snufse1

Programmer
Nov 14, 2008
66
US
I have a proc where I need to condition my "where" clause:

create procedure get_eqmdet
(in @jobnumber char(12)
@costcode char(8),
@suffix char(2),

select ........
where glmcu = @jobnumber and
glsub = @costcode and
case
when @suffix = ' ' then glalty in (' ', 'HR')
when @suffix <> ' ' then glalty = @suffix
end and ......



I am passing in @Suffix as a parm. I am getting error:
Keyword IN not expected. Valid tokens: END.

 
AFAIK a CASE will return a certain VALUE for each record passed. In your situation it returns an expression. I doubt if this is allowed..

Ties Blom

 
This should do the trick
select ........
where glmcu = @jobnumber and
glsub = @costcode and
and (
(@suffix = ' ' and glalty in (' ', 'HR')
or (@suffix <> ' ' and glalty = @suffix)
)


Regards

Frederico Fonseca
SysSoft Integrated Ltd

FAQ219-2884
FAQ181-2886
 
one bracket missing

select ........
where glmcu = @jobnumber and
glsub = @costcode and
and (
(@suffix = ' ' and glalty in (' ', 'HR'))
or (@suffix <> ' ' and glalty = @suffix)
)

Regards

Frederico Fonseca
SysSoft Integrated Ltd

FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top