T-sql Where Clause

Hi
I need to get answer if  Quarter not equal then I need to use Parameter @P2 else i need get all records
see my code below and idea is appriciate

T1.Quarter  IN (CASE WHEN @P2<>'<All>'  THEN @P2  ELSE LIKE '%' END)
AND
T1.Year  IN (CASE WHEN @P3<>'<All>'  THEN @P3  ELSE LIKE '%' END)

I have to use IN Key work ,I cant use Like becuase i need to pass several parameters.This for MS Report 2014, I need to select multiple paratemeters
LVL 10
ukerandiAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
where 
      1 = 
            case when @P2='<All>' then 1 
                      when T1.Quarter in(@P2) then 1 
                       else 0 end 

 AND
           1 = 
                case when @P3 = '<All>' then 1
                         when t1.Year in (@P3) then 1 
                         else 0 end

Open in new window


Note that you may have to split the parameters into a temporary table.  There are plenty of ways to do that but not sure what @p2/@p3 actually represent right now.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ukerandiAuthor Commented:
Great
Kyle AbrahamsSenior .Net DeveloperCommented:
I was thinking about this last night and realized it could be made simpler:
where 
 (@P2 = '<All>' or T1.Quarter in (@P2)) AND
 (@P3 = '<All>' or T1.Year in (@P3))

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SSRS

From novice to tech pro — start learning today.