目的:要格式化这么一段SQL语句(这是随便从网上Copy的一段),没细看内容,反正看到头疼,乱七八糟的不想看。
select b.proj,d.project_name,g.cname,b.id,b.ht_title,isnull(b.htzje,‘0‘) as htzje,isnull(b.yifk,‘0‘) as yifk,sum(isnull(a.je,‘0‘)) as je,g.id as sort from cnto_fk a left join cnto b on a.pid=b.id left join project_table d on b.proj=d.pc_code left join sys_common g on a.fzno=g.cno and g.ctype=‘cnto_htlx‘ where 1=1 and d.project_name is not null and a.title is not null and convert(varchar(10),a.sfkrq,120) between ‘2015-10-01‘ and ‘2015-10-31‘ group by b.proj,d.project_name,g.cname,b.id,b.ht_title,b.htzje,b.yifk,g.id union select a.project_no as proj,d.project_name,g.cname,‘‘ as id,a.title as ht_title,‘0‘ as htzje,sum(isnull(a.je,‘0‘)) as yifk,sum(isnull(a.je,‘0‘)) as je,g.id as sort from cnto_fk a left join project_table d on a.project_no=d.pc_code left join sys_common g on a.fzno=g.cno and g.ctype=‘cnto_htlx‘ where a.fzno=‘qt‘ and d.project_name is not null and a.title is not null and convert(varchar(10),a.sfkrq,120) between ‘2015-10-01‘ and ‘2015-10-31‘ group by a.project_no,d.project_name,g.cname,a.title,g.id order by proj,sort




//8(按Ctrl+A,选中需要格式化的SQL语句),然后点击刚才添加的那个按钮,即刚才的SQL语句就格式化好了
SELECT b.proj, d.project_name, g.cname, b.id, b.ht_title, ISNULL(b.htzje, ‘0‘) AS htzje, ISNULL(b.yifk, ‘0‘) AS yifk, SUM(ISNULL(a.je, ‘0‘)) AS je, g.id AS sort
FROM cnto_fk AS a LEFT OUTER JOIN
cnto AS b ON a.pid = b.id LEFT OUTER JOIN
project_table AS d ON b.proj = d.pc_code LEFT OUTER JOIN
sys_common AS g ON a.fzno = g.cno AND g.ctype = ‘cnto_htlx‘
WHERE (1 = 1) AND (d.project_name IS NOT NULL) AND (a.title IS NOT NULL) AND (CONVERT(varchar(10), a.sfkrq, 120) BETWEEN ‘2015-10-01‘ AND ‘2015-10-31‘)
GROUP BY b.proj, d.project_name, g.cname, b.id, b.ht_title, b.htzje, b.yifk, g.id
UNION
SELECT a.project_no AS proj, d.project_name, g.cname, ‘‘ AS id, a.title AS ht_title, ‘0‘ AS htzje, SUM(ISNULL(a.je, ‘0‘)) AS yifk, SUM(ISNULL(a.je, ‘0‘)) AS je, g.id AS sort
FROM cnto_fk AS a LEFT OUTER JOIN
project_table AS d ON a.project_no = d.pc_code LEFT OUTER JOIN
sys_common AS g ON a.fzno = g.cno AND g.ctype = ‘cnto_htlx‘
WHERE (a.fzno = ‘qt‘) AND (d.project_name IS NOT NULL) AND (a.title IS NOT NULL) AND (CONVERT(varchar(10), a.sfkrq, 120) BETWEEN ‘2015-10-01‘ AND ‘2015-10-31‘)
GROUP BY a.project_no, d.project_name, g.cname, a.title, g.id
ORDER BY proj, sort