SQL语句按in排序

 

根究需求 需要在in里面排序 

sqlserver写法: 

select h.pk_timeitem,h.timeitemcode,h.timeitemname,h.timeitemname2,b.pk_timeitemcopy from tbm_timeitem h 

left join tbm_timeitemcopy b  on b.pk_timeitem = h.pk_timeitem where b.enablestate='2' and h.enablestate='2'  
and h.itemtype='0' and b.pk_org ='pk_org'
 and  timeitemcode in('105','NP','119','PSLHK','115')

ORDER BY CHARINDEX(','+timeitemcode+',',',105,NP,119,PSLHK,115,')"

posted @ 2018-11-12 19:14  NewIand  阅读(1044)  评论(0编辑  收藏  举报