[英]no result from stored procedure, when using temp table [mssql]
I have a stored proc in mssql. 我在mssql中存储了proc。 The SP works fine while executed directly. 直接执行时,SP工作正常。 When i call it in PHP (PHP Version 5.5.13, ZF 1.12.20) i get no result just 当我在PHP(PHP 5.5.13,ZF 1.12.20)中调用它时,我没有得到任何结果
General SQL Server error: Check messages from the SQL Server [4004] (severity 16)
When i remove the part with the temp table it works fine, but thats not an option for me, because i dont own the SP. 当我删除带有临时表的零件时,它工作正常,但这对我来说不是一个选择,因为我不拥有SP。 I shorted the SP to become readable. 我缩短了SP使其变得可读。 It contains about 20 temp tables between 4 differnet SPs, but the problem occurs with every temp table. 它包含4个differnet SP之间的大约20个临时表,但是每个临时表都会出现问题。
$this->_connection = sqlsrv_connect($serverName, $connectionInfo);
...
$this->_stmt = sqlsrv_prepare( $this->connection, 'EXECUTE spBtrgEPM9_test 104215, 37');
...
$stmt->execute($aBindableSpParams);
$aPlainResult = $stmt->fetchAll();
$aResult = array();
foreach ($aPlainResult AS $aRow) {
$sRowClass = $this->getRowClass();
if (!class_exists($sRowClass)) {
Zend_Loader::loadClass($sRowClass);
}
$aResult[] = new $sRowClass(array("data" => $aRow));
}
// Cache result
self::$_aCache[$sSpSpec][$sMd5Hash] = $aResult;
}
return self::$_aCache[$sSpSpec][$sMd5Hash];
SP: SP:
ALTER proc [dbo].[spBtrgEPM9_test]
@arbId int
,@voId int
as begin
set nocount on
set dateformat dmy
SET ANSI_WARNINGS ON
SET ANSI_PADDING ON
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
SET ANSI_NULL_DFLT_ON ON
SET CONCAT_NULL_YIELDS_NULL ON
declare @xml_data xml
Create table #fnDataTable
(
LastName varchar(250)
,FirstName varchar(250)
,DateOfBirth date
,Gender int
,CustomerId int
,CustomerName varchar(250)
,CustomerNumber varchar(250)
,ContributionId int
)
insert into #fnDataTable(
LastName
,FirstName
,DateOfBirth
,Gender
,CustomerId
,CustomerName
,CustomerNumber
,ContributionId
)
exec CalcDB.dbo.GetSalesData @arbId,@voId
declare @xmlValidierung varchar(max)
Set @xmlValidierung = '<?xml version="1.0"?>'+
convert(varchar(max),
(select
(SELECT top 1 y.* FROM #fnDataTable y FOR XML PATH('persondata'), TYPE)
FOR XML PATH(''), ROOT('rentenrechner'))
)
select @xml_data= CONVERT(xml, @xmlValidierung)
select @xml_data as XML_DATA
I can not change the SP. 我无法更改SP。 I could maybe add some lines if there is a fast sollution. 如果可以快速解决问题,我可能会添加一些行。
Solution Part 1: I had two problems. 解决方案第1部分:我有两个问题。 I solved the problem with the temp tables. 我用临时表解决了这个问题。 I had to explicit declare all fields as null. 我必须将所有字段明确声明为null。
Create table #fnDataTable
(
LastName varchar(250) null
,FirstName varchar(250) null
,DateOfBirth date null
,Gender int null
,CustomerId int null
,CustomerName varchar(250) null
,CustomerNumber varchar(250) null
,ContributionId int null
)
I still have the problem, that i cant handle the datatype XML 我仍然有问题,我无法处理XML数据类型
我也遇到了同样的问题,在很多搜索中,我发现在程序的开头添加“ SET NOCOUNT ON”并在最后添加“ SET NOCOUNT OFF”解决了我的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.