有没有办法在这个存储过程中显示select语句的输出?好心提醒 。谢谢你
SET @sSQL = 'SELECT CHDR.CHDRNUM, ZTRN.CCDATE, CHDR.CRDATE, CLNT.CLNTNUM, CLNT.SURNAME, CLNT.GIVNAME,
CLNT.SECUITYNO, ZCLN.EMAIL, CLAM.CLAIM, CLAM.CLMDSC, CLAM.PAID from ((((MPIDTA.ZTRNPF AS ZTRN
LEFT JOIN MPIDTA.CHDRPF AS CHDR ON ZTRN.RLDGACCT = CHDR.CHDRNUM AND ZTRN.EFFDATE = CHDR.CURRFROM)
LEFT JOIN MPIDTA.CLNTPF AS CLNT ON CHDR.COWNNUM = CLNT.CLNTNUM)
LEFT JOIN MPIDTA.ZCLNPF AS ZCLN ON CLNT.CLNTNUM = ZCLN.CLNTNUM)
LEFT JOIN MPIDTA.CLAMPF AS CLAM ON CHDR.CHDRNUM = CLAM.CHDRNUM)
where (ZTRN.BATCPFX = ''BA'' AND ZTRN.BATCCOY = ''1''
AND ZTRN.CNTTYPE = ''PTB'' AND ZTRN.TRANDATE >= ''20150101''
AND (ZTRN.EXPIRY_DATE BETWEEN ' + @FirstDateOfNextMth + ' AND ' + @LastDateOfNextMth + '))
AND (CHDR.MPLNUM = '''' AND CHDR.CHDRPFX = ''CH''
AND CHDR.CHDRCOY = ''1'' AND CHDR.VALIDFLAG = ''1'')
AND (CLAM.DATOCC >= ZTRN.CCDATE AND CLAM.DATOCC <= CHDR.CRDATE)'
SET @sExe = 'Insert into dbo.TPA_Client_Claim_Info Select * FROM OPENQUERY(AS400, ''' + REPLACE(@sSQL, '''', '''''') + ''')'
exec (@sExe)
答案 0 :(得分:0)
SET @sSQL = 'SELECT CHDR.CHDRNUM, ZTRN.CCDATE, CHDR.CRDATE, CLNT.CLNTNUM, CLNT.SURNAME, CLNT.GIVNAME,
CLNT.SECUITYNO, ZCLN.EMAIL, CLAM.CLAIM, CLAM.CLMDSC, CLAM.PAID from ((((MPIDTA.ZTRNPF AS ZTRN
LEFT JOIN MPIDTA.CHDRPF AS CHDR ON ZTRN.RLDGACCT = CHDR.CHDRNUM AND ZTRN.EFFDATE = CHDR.CURRFROM)
LEFT JOIN MPIDTA.CLNTPF AS CLNT ON CHDR.COWNNUM = CLNT.CLNTNUM)
LEFT JOIN MPIDTA.ZCLNPF AS ZCLN ON CLNT.CLNTNUM = ZCLN.CLNTNUM)
LEFT JOIN MPIDTA.CLAMPF AS CLAM ON CHDR.CHDRNUM = CLAM.CHDRNUM)
where (ZTRN.BATCPFX = ''BA'' AND ZTRN.BATCCOY = ''1''
AND ZTRN.CNTTYPE = ''PTB'' AND ZTRN.TRANDATE >= ''20150101''
AND (ZTRN.EXPIRY_DATE BETWEEN ' + @FirstDateOfNextMth + ' AND ' + @LastDateOfNextMth + '))
AND (CHDR.MPLNUM = '''' AND CHDR.CHDRPFX = ''CH''
AND CHDR.CHDRCOY = ''1'' AND CHDR.VALIDFLAG = ''1'')
AND (CLAM.DATOCC >= ZTRN.CCDATE AND CLAM.DATOCC <= CHDR.CRDATE)'
SET @sExe = 'Insert into dbo.TPA_Client_Claim_Info Select * FROM OPENQUERY(AS400, ''' + REPLACE(@sSQL, '''', '''''') + ''')'
SET @sExe = @sExe + ' SELECT * FROM dbo.TPA_Client_Claim_Info'
exec (@sExe) -- OR EXEC SP_EXECUTESQL @sExe