select * from (select isnull(b.lc_type,0) lc_type,isnull(b.cont_oper,'') cont_oper,c.user_name,convert(char(10),b.time_oper,120) as time_oper,c.user_jb_id from bw_bwb a,bw_flow b,oc_user c where a.bwid = 3 and a.bwid = b.bwid and (b.cont_oper <> '') and b.user_id_accept = c.user_id
union
select isnull(b.lc_type,0) lc_type,isnull(b.cont_oper,'') cont_oper,d.dept_name,convert(char(10),b.time_oper,120) as time_oper,null from bw_bwb a,bw_flow b,oc_dept d where a.bwid = 3 and a.bwid = b.bwid and (b.cont_oper <> '')and b.dept_id_accept = d.dept_id ) g order by g.time_oper
union
select isnull(b.lc_type,0) lc_type,isnull(b.cont_oper,'') cont_oper,d.dept_name,convert(char(10),b.time_oper,120) as time_oper,null from bw_bwb a,bw_flow b,oc_dept d where a.bwid = 3 and a.bwid = b.bwid and (b.cont_oper <> '')and b.dept_id_accept = d.dept_id ) g order by g.time_oper
c.user_name,convert(char(10),b.time_oper,120),c.user_jb_id
from bw_bwb a,bw_flow b,oc_user c where a.bwid = 3
and a.bwid = b.bwid and (b.cont_oper <> '') and b.user_id_accept = c.user_id
union
select isnull(b.lc_type,0) lc_type,isnull(b.cont_oper,'')
cont_oper,d.dept_name,convert(char(10),b.time_oper,120),null
from bw_bwb a,bw_flow b,oc_dept d where a.bwid = 3 and a.bwid = b.bwid and (b.cont_oper <> '')and
b.dept_id_accept = d.dept_id
order by convert(char(10),b.time_oper,120)