我想将存储过程结果传递给 ColdFusion 中的另一个存储过程。如果有人能在这方面提供帮助。
<cfif not isDefined("getYN")>
<cfstoredproc procedure="stored_proc" datasource="#dsn#">
<cfprocparam cfsqltype="cf_sql_varchar" dbvarname="@lang" type="in" value="#this.lang#"/>
<cfprocparam cfsqltype="cf_sql_varchar" dbvarname="@sqlStatement" type="in" value="#getYN#" null="#NOT len(trim(getYN))#" />
<cfprocresult name="getYN" resultset = "1">
</cfstoredproc>
</cfif>
<cfstoredproc procedure="sp_test" datasource="#dsn#">
<cfprocparam cfsqltype="cf_sql_varchar" dbvarname="@lang" type="in" value="#this.lang#"/>
<cfprocparam cfsqltype="cf_sql_varchar" dbvarname="@sqlStatement" type="in" value="#getYN#" null="#NOT len(trim(getYN))#" />
<cfprocresult name="get" resultset = "2">
</cfstoredproc>
以上是代码示例。在第二个存储过程中,我将第一个存储过程的结果传递给第二个存储过程的 dbvarname sqlStatement。但是传递的值 #getYN# 应该是查询而不是结果,因为我将它用于 FROM 子句。
SQL Server 中的第二个存储过程如下所示:
ALTER PROCEDURE [dbo].[sp_test]
@lang CHAR(5),
@code VARCHAR(20),
@sqlStatement NVARCHAR(MAX) = NULL
AS
BEGIN
SET NOCOUNT ON;
DECLARE @sSQL nVARCHAR(max)
SET @sSQL = ' SELECT col1
FROM '+ @sqlStatement +
' WHERE col2 = @lang
AND col3 = @code '
EXECUTE SP_EXECUTESQL @sSQL, N'@lang CHAR(5),
@code VARCHAR(20)', @lang, @code ;
SET NOCOUNT OFF;
END
另外,上面两段代码是根据下面的代码创建的,用cfstoredproc代替cfquery:
<cfif NOT isDefined("request.getYN")>
<cfquery name="request.getYN" datasource="#request.dsn.pqr#">
SELECT
LANGUAGE_CODE ,
YN_CODE ,
YN_DESCRIPTION
FROM
LANGUAGE_ALTS_YN
WHERE
language_code IN (
'EN','#this.lang#'
)
</cfquery>
</cfif>
<cfquery name="get" dbtype="query">
SELECT
yn_description
FROM
request.getYN
WHERE
language_code =
<cfqueryparam cfsqltype="cf_sql_varchar" value="#this.lang#" />
AND yn_code = <cfqueryparam cfsqltype="cf_sql_varchar"
value="#arguments.code#" />
</cfquery>