请教解析
fanbo 2006-05-10 01:32:54 if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[USP_xm_dtcb_rpt]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[USP_xm_dtcb_rpt]
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS OFF
GO
CREATE PROCEDURE dbo.USP_xm_dtcb_rpt(@strProjectCode varchar(40))
WITH ENCRYPTION
AS
SELECT project_code,
project_name,
cost_code,
cost_name,
(case when ht_cost.cifnext = 1 then space((ht_cost.clevel - 1)*2) + ht_cost.cost_name
else space((ht_cost.clevel - 1)*2) + ht_cost.cost_name end) as new_cost_name,
target_cost,
dt_cost,
' ' as jysm,
cifnext,
CONVERT(VARCHAR(80),' ') as yf_unit,
CONVERT(VARCHAR(80),' ') as ht_code,
CONVERT(VARCHAR(80),' ') as ht_name,
0 as ht_amount,
0 as bg_amount,
0 as sf_amount,
( select isnull(sum(cf_amount),0)
from cfmx
where CHARINDEX(@strProjectCode + '.' ,cfmx.project_code + '.') = 1
and CHARINDEX(ht_cost.cost_code + '.' ,cfmx.km_code + '.') = 1
and (cfmx.cfly ='合同' or cfmx.cfly ='材料')) as htcf_amount,
( select isnull(sum(cf_amount),0)
from cfmx
where CHARINDEX(@strProjectCode + '.' ,cfmx.project_code + '.') = 1
and CHARINDEX(ht_cost.cost_code + '.' ,cfmx.km_code + '.') = 1
and cfmx.cfly ='变更') as bgcf_amount,
( select isnull(sum(cf_amount),0)
from cfmx
where CHARINDEX(@strProjectCode + '.' ,cfmx.project_code + '.') = 1
and CHARINDEX(ht_cost.cost_code + '.' ,cfmx.km_code + '.') = 1
and cfmx.cfly ='实付') as htsf_amount
INTO #DTCB_TABLE
FROM ht_cost
WHERE project_code = @strProjectCode
ORDER BY cost_code
INSERT INTO #DTCB_TABLE
SELECT @strProjectCode as project_code,
(select xm_name from ht_xm_setup where xm_code = @strProjectCode) as project_name,
cfmx.km_code as cost_code,
cfmx.km_name as cost_name,
(select new_cost_name from #DTCB_TABLE
where cost_code = cfmx.km_code) as new_cost_name,
(select target_cost from ht_cost
where project_code = @strProjectCode
and cost_code = cfmx.km_code) as target_cost,
(select dt_cost from ht_cost
where project_code = @strProjectCode
and cost_code = cfmx.km_code) as dt_cost,
'' as jysm,
'9' as cifnext,
ht_mng.yf_unit,
ht_mng.ht_code,
ht_mng.ht_name,
ht_mng.ht_amount,
ht_mng.sum_bgamount,
ht_mng.sum_sfamount,
sum(Case When cfly ='合同' or cfly ='材料' Then cf_amount Else 0 End ) as htcf_amount,
sum(Case When cfly ='变更' Then cf_amount Else 0 End ) as bgcf_amount,
sum(Case When cfly ='实付' Then cf_amount Else 0 End ) as htsf_amount
FROM ht_mng,cfmx
WHERE ht_mng.ht_code = cfmx.ht_code
AND CHARINDEX(@strProjectCode + '.', cfmx.project_code + '.') = 1
GROUP BY cfmx.km_code,cfmx.km_name,ht_mng.yf_unit,ht_mng.ht_code,ht_mng.ht_name,ht_mng.ht_amount,ht_mng.sum_bgamount,ht_mng.sum_sfamount
SELECT * FROM #DTCB_TABLE ORDER BY COST_CODE,HT_CODE,PROJECT_CODE
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
这个存储过程请高手解析一下,我主要想知道的是 select ....into 与 insert into 的主要区别。