为数组中的每个 val 运行存储过程
我无法理解这个问题..
我有两个单独的存储过程,我们称它们为:
createTable (takes a varchar userID as input)
runReport (takes two dates for input, as varchar)
createTable 创建一个名为 ##tempTable 的虚拟表(如果它不存在,则添加提供的 userID)。因此,如果我运行
EXEC createTable 'user-32'
EXEC createTable 'user-33'
EXEC createTable 'user-34'
,那么这些 ID 就会存储在 ##tempTable 中。
之后我想运行这个:
EXEC runReport '2011-01-01', '2011-10-01'
这应该会给我一个很大的美味输出。 问题是,当像这样运行它时,它可以完美地工作:
mssql_query("EXEC createTable 'user-32'");
mssql_query("EXEC createTable 'user-33'");
mssql_query("EXEC createTable 'user-34'");
mssql_query("EXEC runReport '2011-01-01', '2011-10-01'");
但是当我尝试循环出 createTable-lines 时,runReport-SP 不会返回任何数据。
示例:
$userIDs = explode(',', $userID_str);
foreach ($userIDs as $user) {
if (mb_strlen($user) > 0) {
mssql_query("EXEC createTable '$user'");
}
}
我想知道这是否与连接断开或其他原因有关?看来 runReport-SP 可以找到#tempTable,但当我使用循环时它无法从中读取。
有什么想法吗?
谢谢! :)
Can't wrap my head around this one..
I have two separate stored procedures, let's call them:
createTable (takes a varchar userID as input)
runReport (takes two dates for input, as varchar)
createTable creates a virtual table called ##tempTable (if it doesn't exists and add the provided userID). So if I run
EXEC createTable 'user-32'
EXEC createTable 'user-33'
EXEC createTable 'user-34'
I then have these IDs in ##tempTable.
After that I want to run this:
EXEC runReport '2011-01-01', '2011-10-01'
Which should give me a big tasty output.
The thing is that this works flawlessly when running it like so:
mssql_query("EXEC createTable 'user-32'");
mssql_query("EXEC createTable 'user-33'");
mssql_query("EXEC createTable 'user-34'");
mssql_query("EXEC runReport '2011-01-01', '2011-10-01'");
But when I try to loop out the createTable-lines the runReport-SP doesn't return any data.
Example:
$userIDs = explode(',', $userID_str);
foreach ($userIDs as $user) {
if (mb_strlen($user) > 0) {
mssql_query("EXEC createTable '$user'");
}
}
I'm wondering if this could have anything to do with a broken connection or something? It seems that the runReport-SP can find the #tempTable but it can't read from it when I use a loop.
Any ideas?
Thanks! :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那么以这种方式调用你的程序怎么样:
?
And what about calling Your procedures this way:
?