SELECT CONVERT ( VARCHAR ( 10 ), c.InputTime, 23 ) AS 对比年月, c.CONTRACTSUM AS 本月金额, d.CONTRACTSUM AS 去年同期金额, CASE WHEN d.CONTRACTSUM IS NULL OR d.CONTRACTSUM= 0 THEN '无穷大' ELSE CAST ( CAST ( ( isnull( c.CONTRACTSUM, 0 ) - isnull( d.CONTRACTSUM, 0 ) ) * 100 / isnull( d.CONTRACTSUM, 0 ) AS DECIMAL ( 10, 2 ) ) AS VARCHAR ( 50 ) ) + '%' END AS 同比 FROM dbo.outCONTRACT c LEFT JOIN ( SELECT a.CONTRACTSUM AS CONTRACTSUM, a.InputTime AS lsInputTime, b.InputTime AS InputTime FROM dbo.outCONTRACT a JOIN dbo.outCONTRACT b ON a.InputTime= DateAdd( YEAR, - 1, b.InputTime ) ) d ON c.InputTime= d.InputTime |