join condition depends on the parameter

Posted by sunglim on Stack Overflow See other posts from Stack Overflow or by sunglim
Published on 2010-05-10T04:21:10Z Indexed on 2010/05/10 4:28 UTC
Read the original article Hit count: 389

Filed under:
|

Hi. I'm a sql newbie, I use mssql2005

I like to do join Action depnding on input parameter.

CREATE PROCEDURE SelectPeriodicLargeCategoryData 
    @CATEGORY_LEVEL CHAR(1),
    @CATEGORY_CODE VARCHAR(9)
AS

...


JOIN CATEGORY_AD_SYS CAS WITH(NOLOCK)
ON CA.CATEGORY_ID = [[[[[   HERE      ]]]]

above the sql.
if @CATEGORY_LEVEL = 'L' then I like to join on CAS.LCATEGORY

else if @CATEGORY_LEVEL = 'M' then I like to join on CAS.MCATEGORY

else if @CATEGORY_LEVEL = 'S' then I like to join on CAS.SCATEGORY

...

how can I do this?

© Stack Overflow or respective owner

Related posts about sql

Related posts about stored-procedures