简体   繁体   English

为什么来自SQL Server 2000的简单SQL查询在SQL Server 2008中会有不同的结果?

[英]Why does this simple SQL query from SQL Server 2000 have different results in SQL Server 2008?

Using MS SQL 2000 it was possible to have a query such as: 使用MS SQL 2000可以进行如下查询:

SELECT (Code + ' = ' + EdiNumber + ',') AS MyResult FROM tblCountry

Which would give you a list of results like: 这将为您提供结果列表,例如:

MyResult
========
ZW = 263,
ZA = 27,
...

However, in MS SQL 2008 that query returns: 但是,在MS SQL 2008中,该查询返回:

-1 records affected

Does anyone know a) Why? 有谁知道a)为什么? and b) How to get the SQL 2000 result from SQL 2008? b)如何从SQL 2008获取SQL 2000结果?

UPDATE 更新

Im just using a standard ASP.NET connection string to connect to the database using a console to post the query: 我只是使用标准的ASP.NET连接字符串使用控制台发布查询来连接到数据库:

Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\MyDB.mdf;Integrated Security=True;User Instance=True; Database=MyDB

PROBLEM SOLVED 问题解决了

-1 records affected was clearly the non-privileged result because all that was actually happening was an error in the query whilst trying to concatenate a string (Code) and an int (EdiNumber) -1 records affected显然是非特权结果,因为所有实际发生的都是查询中的错误,同时尝试连接string (Code)和int (EdiNumber)

The correct query should have been: 正确的查询应该是:

SELECT (Code + ' = ' + CAST(EdiNumber AS VARCHAR) + ',') as MyResult FROM tblCountry

Once I got that correct, the query worked fine from the original console. 一旦确定正确,该查询就可以在原始控制台中正常运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM