# Database Discussions > Microsoft SQL Server 2008 >  select Case when query help

## Lava

Hi - I have two tables (tbl1 and tbl2).  based on m_code value in tbl1, I want to displayP_CODE and E_CODE fields in tbl2 certain way. Below is how I need to write my query to show how I need to display the field values, I appreciate if you please help me with correcting the query!


select 
case 
when  e.m_code = 'S' then s.P_CODE = 1 and s.E_CODE = 1
when e.m_code = 'H' then s.P_CODE = 2 and s.E_CODE =1
when e.m_code = 'E' then s.P_CODE = 3 and s.E_CODE =1
when e.m_code = 'P' then s.P_CODE = 3 and s.E_CODE = 1
when e.m_code ='R' then s.P_CODE = 3 and s.E_CODE =1 
end
from
tbl1 e
join  tbl2 s on e.field = s.field
where s.m_code in (
'S',
'H',
'E',
'P',
'R')

----------


## skhanal

Not clear how you want P_CODE and E_CODE displayed. The current query is not syntactically correct.

----------


## Lava

I already resolved the issue, thank you..

----------

