2

我从 PHP 和 SSManagement Studio 查询 MSSQL 过程,结果不同??

此查询从表中获取以 tKey 开头的字段。存在两列 tKey1 和 tKey2

程序sp_myProc

DECLARE @tKeys VARCHAR(100);

SELECT @tKeys = ISNULL(@tKeys + ',', '') + column_name
FROM   testweberp.INFORMATION_SCHEMA.columns
WHERE  table_name = myTable
       AND LEFT(column_name, 4) = 'tKey'
ORDER  BY ordinal_position;

SELECT @tKeys 

当我从 SSMS 执行查询时,exec sp_myProc,我得到了结果:tKey1,tKey2

当我从 php, 执行查询时mssql_query("exec sp_myProc",$link),我得到结果:,tKey1,tKey2

是的,发送到 php 的结果中有一个额外的逗号它不是由 php 产生的,因为如果不是@tKeys,我返回len(@tKeys),它11在 SSMS 和12php 中?

4

1 回答 1

5

It seems SET CONCAT_NULL_YIELDS_NULL may be the culprit.

Using a similar query on one of my databases returns no leading comma for SET CONCAT_NULL_YIELDS_NULL ON, and a leading comma for SET CONCAT_NULL_YIELDS_NULL OFF.

Note that (from MSDN)

The setting of SET CONCAT_NULL_YIELDS_NULL is set at execute or run time and not at parse time.

于 2012-10-22T11:19:46.510 回答