Hello
I want to put a case statement into a where clause but it's not working. Can anybody help, or tell me a better way of doing this
Thanks very much
declare @.param varchar (100)
select @.param = 'mytext
select
colA
,colB
,colC
from
mytable
where
(case
when @.param is null then colA = 'group'
else colA = 'single'
end)I'd suggest using WHERE colA = CASE WHEN @.param IS NULL THEN 'group' ELSE 'single' END-PatP|||No I can't do it like that
I've rewritten what I want, maybe you can hlp with this
declare @.param varchar (100)
select @.param = 'mytext'
select
colA
,colB
,colC
from
mytable
where
(case
when @.param is null then colB = 'group' and colC = 'something'
else colB = 'group' and colC = @.param
end)|||Ok, let's do that dance and move on to:SELECT
colA
, colB
, colC
FROM mytable
WHERE (@.param IS NULL AND colB = 'group' AND colC = 'something')
OR (@.param = colC AND colB = 'group')-PatP
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment