日期:2014-05-18  浏览次数:20391 次

我有个存储过程,找不出来问题,向高手请教!
CREATE PROCEDURE [dbo].[REPORT_FEE_TEST]
-- @REPORTTYPE VARCHAR(20),
@PLATFORM VARCHAR(20),
@SETTLEMENTTIMEBEGIN VARCHAR(20),
@SETTLEMENTTIMEEND VARCHAR(20),
@PAYTIMEBEGIN VARCHAR(20),
@PAYTIMEEND VARCHAR(20)
 AS
DECLARE @SQLSTR VARCHAR(8000)
DECLARE @SQLFIELD1 VARCHAR(8000)
DECLARE @SQLFIELD2 VARCHAR(8000)
DECLARE @SQLFIELD3 VARCHAR(8000)
DECLARE @SQLFIELD4 VARCHAR(8000)
DECLARE @SQLCode VARCHAR(400)
DECLARE @SQLNAME VARCHAR(400)

DECLARE cur_FeeItem Cursor FOR
SELECT
CODE,NAME
FROM
CodeTable 
WHERE 
CodeType='FeeItem' Order By CodeId

OPEN cur_FeeItem
FETCH NEXT FROM cursor_FeeItem INTO @SQLCode,@SQLName
WHILE @@FETCH_STATUS = 0

BEGIN

SET @SQLFIELD1=@SQLFIELD1 +',0.00 AS '+@SQLCode
SET @SQLFIELD2=@SQLFIELD2+',order'+@SQLCode+'.ComFee AS'+@SQLCode
SET @SQLFIELD3=@SQLFIELD3+',orderfee AS order'+@SQLCode
SET @SQLFIELD4=@SQLFIELD4+' AND a.SapOrd = order'+@SQLCode+'.SapOrd and order'+@SQLCode+'.feeitem ='+@SQLCode

FETCH NEXT FROM cursor_FeeItem INTO @SQLCode,@SQLName
END
CLOSE cursor_FeeItem
DEALLOCATE cursor_FeeItem

SET @SQLSTR='
select a.DeatLike,b.ComFee AS MainFee '+@SQLFIELD1 +'
from tmsorder a,orderfee b,
(select 
tranno 
from 
trannofee 
where 
FeeSMStatus = '''0''' 
group by tranno) c,
SettlementDetail d,
Settlement e
where 
a.SapOrd = b.SapOrd
and a.tranno =c.tranno
and a.tranno = d.tranno
and d.SettlementNo =e.SettlementNo
and b.feeitem = '''MainFee'''
and e.SettlementTime >= @SettlementTimeBegin 
  and e.SettlementTime <= '''@SettlementTimeEnd''' 
and b.paytime >= @PAYTIMEBEGIN and b.paytime <= @PAYTIMEEND

union

select 
a.DeatLike,0.00 AS MainFee,'+@SQLFIELD2+ ' 
from 
tmsorder a,
(select 
invoice 
from 
invoicefee 
where 
FeeSMStatus = '''0''' 
group by invoice ) as c
SettlementDetail d, Settlement e '+@SQLFIELD3+ '

where 
a.invoice =c.invoice
and a.tranno = d.tranno
and d.SettlementNo=e.SettlementNo '+@SQLFIELD4+ '
and e.SettlementTime >= '''@SettlementTimeBegin'''and e.SettlementTime <= '''@SettlementTimeEnd''' 
and b.paytime >= '''@PAYTIMEBEGIN''' and b.paytime <= '''@PAYTIMEEND''''


------解决方案--------------------
' ' 'MainFee ' ' ' 

字符串的'=''