sql-server - 将整数列表传递给存储过程

标签 sql-server coldfusion

这是我的存储过程:

ALTER PROCEDURE [dbo].[Dan] 
@numbers varchar(10)    
AS
BEGIN
SET NOCOUNT ON;
select @numbers numbers
END

在SSMS中,我可以像这样成功执行它:

exec dbo.Dan '1.2' 

在 ColdFusion 中,我可以使用这两组命令中的任何一个成功执行它:

<cfstoredproc procedure="dbo.dan" datasource="ClinicalDataDev">
<cfprocparam cfsqltype="cf_sql_varchar" value="1,2"> 
<cfprocresult name="abc">
</cfstoredproc>

<cfquery name="abcd" datasource="ClinicalDataDev">
exec dbo.Dan <cfqueryparam cfsqltype="cf_sql_varchar" value='1,2' list="no">
</cfquery>

但是,我希望通过将值指定为整数列表来改进这一点。由于 cfprocparam 没有列表属性,因此我认为我仅限于 cfquery 方法。到目前为止我的努力和成果是:

<cfqueryparam cfsqltype="cf_sql_integer" value='1' list="no">
executes successfully.  The purpose is to see if the procedure accepts an 
integer - it does.

<cfqueryparam cfsqltype="cf_sql_integer" value='1,2' list="no">
also executes sucessfully, but returns a value of 42006.  Probably not 
worth persuing.

<cfqueryparam cfsqltype="cf_sql_integer" value='1,2' list="yes">
throws an error for two many paramters.  
The same thing happens with cf_sql_varchar.

如前所述,我可以将列表作为字符串传递,但这似乎有点麻烦。有没有办法将整数列表作为整数列表传递?

最佳答案

正如其他评论者之前提到的,传递表值参数是正确的方法。这将要求您更改 SP 中的输入以采用表输入,并且在您的查询中您可以执行以下操作

<cfquery>
    CREATE TABLE @temp (usedID int)
    INSERT INTO @temp 
        (usedID)
        VALUES
        (1)
        ,(2)

    exec dbo.Dan @temp
</cfquery>

您可能必须更改将参数传递给 SP 的方式,但这是一般想法。

关于sql-server - 将整数列表传递给存储过程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30108973/

相关文章:

utf-8 - 在 ColdFusion 中记录 UTF-8 字符

jquery - IE 中非常奇怪的 url,页面 404 错误

ssl - 从 coldfusion 发送推送通知?

iis-7 - 使用 Windows 身份验证的 IIS 7.5 上的 ColdFusion 9 的正确权限是什么

java - SQL 异常 com.microsoft.sqlserver.jdbc.sqlserverexception : login failed for user '' . Clientconnectionid:073b35b2-0e56-460d-8353-9de2b2d0ecff

sql - 在 UNION ALL 结果集中使用聚合函数

coldfusion - ColdFusion 计划任务是否有默认超时?

sql - "There is already an object named XXXX in the database"创建新数据库后

c# - 林克 2 SQL : composite primary key

sql - 全文搜索仅偶尔查找单词