|
 |
 |
 |
 |
Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms
of Use |
Trademarks
Article ID: 975417 - Last Review: October 19, 2009 - Revision: 1.1 FIX: A SELECT statement returns an incorrect result set if a linked server is being used in SQL Server 2005 or in SQL Server 2008Microsoft distributes Microsoft SQL Server 2005 fixes as one downloadable file. Because the fixes are cumulative, each new release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2005 fix release.Microsoft distributes Microsoft SQL Server 2008 fixes as one downloadable file. Because the fixes are cumulative, each new release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 fix release. In Microsoft SQL Server 2005 or in Microsoft SQL Server 2008, you run a SELECT statement across tables that use a linked server as a data source, and an incorrect result set is returned. SQL Server 2005 Service Pack 3
The fix for this issue was first released in Cumulative Update 6 for SQL Server 2005 Service Pack 3. For more information about this cumulative update package, click the following article number to view the article in the Microsoft Knowledge Base: 974648Â
(http://kbalertz.com/Feedback.aspx?kbNumber=974648/
)
Cumulative update package 6 for SQL Server 2005 Service Pack 3 Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2005 fix release. Microsoft recommends that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base: 960598Â
(http://kbalertz.com/Feedback.aspx?kbNumber=960598/
)
The SQL Server 2005 builds that were released after SQL Server 2005 Service Pack 3 was released
Microsoft SQL Server 2005 hotfixes are created for specific SQL Server service packs. You must apply a SQL Server 2005 Service Pack 3 hotfix to an installation of SQL Server 2005 Service Pack 3. By default, any hotfix that is provided in a SQL Server service pack is included in the next SQL Server service pack.
The release version of SQL Server 2008Important You must install this fix if you are running the release version of SQL Server 2008. The fix for this issue was first released in Cumulative Update 8. For more information about how to obtain this cumulative update package for SQL Server 2008, click the following article number to view the article in the Microsoft Knowledge Base: 975976Â
(http://kbalertz.com/Feedback.aspx?kbNumber=975976/
)
Cumulative update package 8 for SQL Server 2008 Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 fix release. We recommend that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base: 956909Â
(http://kbalertz.com/Feedback.aspx?kbNumber=956909/
)
The SQL Server 2008 builds that were released after SQL Server 2008 was released SQL Server 2008 Service Pack 1Important You must install this fix if you are running SQL Server 2008 Service Pack 1.
The fix for this issue was first released in Cumulative Update 5 for SQL Server 2008 Service Pack 1. For more information about this cumulative update package, click the following article number to view the article in the Microsoft Knowledge Base: 975977Â
(http://kbalertz.com/Feedback.aspx?kbNumber=975977/
)
Cumulative update package 5 for SQL Server 2008 Service Pack 1 Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 fix release. Microsoft recommends that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base: 970365Â
(http://kbalertz.com/Feedback.aspx?kbNumber=970365/
)
The SQL Server 2008 builds that were released after SQL Server 2008 Service Pack 1 was released
Microsoft SQL Server 2008 hotfixes are created for specific SQL Server service packs. You must apply a SQL Server 2008 Service Pack 1 hotfix to an installation of SQL Server 2008 Service Pack 1. By default, any hotfix that is provided in a SQL Server service pack is included in the next SQL Server service pack.
Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the "Applies to" section. Steps to reproduce the problemThe following sample statements can be used to reproduce this problem.
-- create sample database
--
create database test
go
use test
go
--
-- create sample table
--
if exists (select * from sys.objects where object_id = OBJECT_ID('T1'))
drop table T1
create table T1 (
ID int primary key,
CODE_AB char(2) not null,
CATEGORY char(1) not null default ('0')
)
if exists (select * from sys.objects where object_id = OBJECT_ID('M1'))
drop table M1
create table M1 (
CODE_AB char(2) primary key,
[NAME] varchar(20) not null
)
insert into T1 (ID, CODE_AB) values ( 1, '66')
insert into T1 (ID, CODE_AB) values ( 2, '66')
insert into T1 (ID, CODE_AB) values ( 3, '77')
insert into T1 (ID, CODE_AB) values ( 4, '55')
insert into T1 (ID, CODE_AB) values ( 5, '88')
insert into T1 (ID, CODE_AB) values ( 6, '88')
insert into T1 (ID, CODE_AB) values ( 7, '77')
insert into T1 (ID, CODE_AB) values ( 8, '66')
insert into T1 (ID, CODE_AB) values ( 9, '77')
insert into T1 (ID, CODE_AB) values ( 10, '66')
insert into T1 (ID, CODE_AB) values ( 11, '66')
insert into T1 (ID, CODE_AB) values ( 12, '88')
insert into T1 (ID, CODE_AB) values ( 13, '88')
insert into T1 (ID, CODE_AB) values ( 14, '88')
insert into T1 (ID, CODE_AB) values ( 15, '22')
insert into T1 (ID, CODE_AB) values ( 16, '88')
insert into T1 (ID, CODE_AB) values ( 17, '88')
insert into T1 (ID, CODE_AB) values ( 18, '88')
insert into T1 (ID, CODE_AB) values ( 19, '44')
insert into T1 (ID, CODE_AB) values ( 20, '88')
insert into T1 (ID, CODE_AB) values ( 21, '66')
insert into T1 (ID, CODE_AB) values ( 22, '66')
insert into T1 (ID, CODE_AB) values ( 23, '77')
insert into T1 (ID, CODE_AB) values ( 24, '77')
insert into T1 (ID, CODE_AB) values ( 25, '77')
insert into T1 (ID, CODE_AB) values ( 26, '66')
insert into T1 (ID, CODE_AB) values ( 27, '66')
insert into T1 (ID, CODE_AB) values ( 28, '66')
insert into T1 (ID, CODE_AB) values ( 29, '44')
insert into T1 (ID, CODE_AB) values ( 30, '77')
insert into T1 (ID, CODE_AB) values ( 31, '44')
insert into T1 (ID, CODE_AB) values ( 32, '66')
insert into T1 (ID, CODE_AB) values ( 33, '88')
insert into T1 (ID, CODE_AB) values ( 34, '88')
insert into T1 (ID, CODE_AB) values ( 35, '66')
insert into T1 (ID, CODE_AB) values ( 36, '66')
insert into T1 (ID, CODE_AB) values ( 37, '77')
insert into T1 (ID, CODE_AB) values ( 38, '77')
insert into T1 (ID, CODE_AB) values ( 39, '77')
insert into T1 (ID, CODE_AB) values ( 40, '44')
insert into T1 (ID, CODE_AB) values ( 41, '77')
insert into T1 (ID, CODE_AB) values ( 42, '77')
insert into T1 (ID, CODE_AB) values ( 43, '66')
insert into T1 (ID, CODE_AB) values ( 44, '66')
insert into T1 (ID, CODE_AB) values ( 45, '77')
insert into T1 (ID, CODE_AB) values ( 46, '44')
insert into T1 (ID, CODE_AB) values ( 47, '66')
insert into T1 (ID, CODE_AB) values ( 48, '66')
insert into T1 (ID, CODE_AB) values ( 49, '66')
insert into T1 (ID, CODE_AB) values ( 50, '88')
insert into T1 (ID, CODE_AB) values ( 51, '66')
insert into T1 (ID, CODE_AB) values ( 52, '44')
insert into T1 (ID, CODE_AB) values ( 53, '88')
insert into T1 (ID, CODE_AB) values ( 54, '88')
insert into T1 (ID, CODE_AB) values ( 55, '88')
insert into T1 (ID, CODE_AB) values ( 56, '88')
insert into T1 (ID, CODE_AB) values ( 57, '22')
insert into T1 (ID, CODE_AB) values ( 58, '88')
insert into T1 (ID, CODE_AB) values ( 59, '11')
insert into T1 (ID, CODE_AB) values ( 60, '11')
insert into T1 (ID, CODE_AB) values ( 61, '11')
insert into T1 (ID, CODE_AB) values ( 62, '88')
insert into T1 (ID, CODE_AB) values ( 63, '77')
insert into T1 (ID, CODE_AB) values ( 64, '77')
insert into T1 (ID, CODE_AB) values ( 65, '66')
insert into T1 (ID, CODE_AB) values ( 66, '77')
insert into T1 (ID, CODE_AB) values ( 67, '77')
insert into T1 (ID, CODE_AB) values ( 68, '77')
insert into T1 (ID, CODE_AB) values ( 69, '33')
insert into T1 (ID, CODE_AB) values ( 70, '33')
insert into T1 (ID, CODE_AB) values ( 71, '66')
insert into T1 (ID, CODE_AB) values ( 72, '66')
insert into T1 (ID, CODE_AB) values ( 73, '66')
insert into T1 (ID, CODE_AB) values ( 74, '11')
insert into T1 (ID, CODE_AB) values ( 75, '77')
insert into T1 (ID, CODE_AB) values ( 76, '11')
insert into T1 (ID, CODE_AB) values ( 77, '66')
insert into T1 (ID, CODE_AB) values ( 78, '66')
insert into T1 (ID, CODE_AB) values ( 79, '66')
insert into T1 (ID, CODE_AB) values ( 80, '66')
insert into T1 (ID, CODE_AB) values ( 81, '66')
insert into T1 (ID, CODE_AB) values ( 82, '66')
insert into T1 (ID, CODE_AB) values ( 83, '66')
insert into T1 (ID, CODE_AB) values ( 84, '66')
insert into T1 (ID, CODE_AB) values ( 85, '66')
insert into T1 (ID, CODE_AB) values ( 86, '66')
insert into T1 (ID, CODE_AB) values ( 87, '77')
insert into T1 (ID, CODE_AB) values ( 88, '77')
insert into T1 (ID, CODE_AB) values ( 89, '66')
insert into T1 (ID, CODE_AB) values ( 90, '11')
insert into T1 (ID, CODE_AB) values ( 91, '88')
insert into T1 (ID, CODE_AB) values ( 92, '88')
insert into T1 (ID, CODE_AB) values ( 93, '44')
insert into T1 (ID, CODE_AB) values ( 94, '66')
insert into T1 (ID, CODE_AB) values ( 95, '77')
insert into T1 (ID, CODE_AB) values ( 96, '44')
insert into T1 (ID, CODE_AB) values ( 97, '77')
insert into T1 (ID, CODE_AB) values ( 98, '77')
insert into T1 (ID, CODE_AB) values ( 99, '88')
insert into T1 (ID, CODE_AB) values (100, '88')
insert into T1 (ID, CODE_AB) values (101, '88')
insert into T1 (ID, CODE_AB) values (102, '77')
insert into T1 (ID, CODE_AB) values (103, '66')
insert into T1 (ID, CODE_AB) values (104, '77')
insert into M1 values ('66', 'F')
insert into M1 values ('77', 'G')
if exists (select srv.name from sys.servers srv where srv.name = '127.0.0.1')
exec sp_dropserver @server = '127.0.0.1', @droplogins = 'droplogins'
exec sp_addlinkedserver @server = '127.0.0.1', @srvproduct = 'SQL Server'
exec sp_addlinkedsrvlogin @rmtsrvname = '127.0.0.1', @useself = 'True', @locallogin = NULL, @rmtuser = NULL, @rmtpassword = NULL
go
--
-- compare results.
--
-- 1. select local tables. -> expect a correct result.
select *
from (
select
ID,
CODE_AB,
CODE_A = case when CATEGORY = '0' then substring(T1.CODE_AB, 1, 1) end,
CODE_B = case when CATEGORY = '0' then substring(T1.CODE_AB, 2, 1) end,
CODE_NAME = case when CATEGORY = '0' then (
select
M1.CODE_AB + ' ' + M1.[NAME]
from M1
where M1.CODE_AB = T1.CODE_AB
) end
from T1
) as TEMP
where CODE_A = '7' and CODE_B = '7'
-- 2. select tables via linked server. -> expect a wrong result.
select *
from (
select
ID,
CODE_AB,
CODE_A = case when CATEGORY = '0' then substring(T1.CODE_AB, 1, 1) end,
CODE_B = case when CATEGORY = '0' then substring(T1.CODE_AB, 2, 1) end,
CODE_NAME = case when CATEGORY = '0' then (
select
M1.CODE_AB + ' ' + M1.[NAME]
from [127.0.0.1].test.dbo.M1 as M1
where M1.CODE_AB = T1.CODE_AB
) end
from [127.0.0.1].test.dbo.T1 as T1
) as TEMP
where CODE_A = '7' and CODE_B = '7'
--order by CODE_AB -- if we use this the correct result will return.
go
--
-- drop linked server, drop sample database.
--
/*
if exists (select srv.name from sys.servers srv where srv.name = '127.0.0.1')
exec sp_dropserver @server = '127.0.0.1', @droplogins = 'droplogins'
use master
go
if exists (select * from sys.databases where name = 'TEST')
drop database test
*/
For more informationabout the Incremental Servicing Model for SQL Server, click the following article number to view the article in the Microsoft Knowledge Base:
935897Â
(http://kbalertz.com/Feedback.aspx?kbNumber=935897/
)
An Incremental Servicing Model is available from the SQL Server team to deliver hotfixes for reported problems
For more informationabout how to obtain SQL Server 2005 Service Pack 3, click the following article number to view the article in the Microsoft Knowledge Base:
913089Â
(http://kbalertz.com/Feedback.aspx?kbNumber=913089/
)
How to obtain the latest service pack for SQL Server 2005
For more information about the new features in SQL Server 2005 Service Pack 3 (SP3) and about the improvements in SQL Server 2005 SP3, visit the following Microsoft Web site:
For more informationabout the naming schema for SQL Server updates, click the following article number to view the article in the Microsoft Knowledge Base:
822499Â
(http://kbalertz.com/Feedback.aspx?kbNumber=822499/
)
New naming schema for Microsoft SQL Server software update packages
For more information about software update terminology, click the following article number to view the article in the Microsoft Knowledge Base:
824684Â
(http://kbalertz.com/Feedback.aspx?kbNumber=824684/
)
Description of the standard terminology that is used to describe Microsoft software updates
APPLIES TO- Microsoft SQL Server 2005 Standard Edition
- Microsoft SQL Server 2005 Enterprise Edition
- Microsoft SQL Server 2005 Developer Edition
- Microsoft SQL Server 2005 Workgroup Edition
- Microsoft SQL Server 2005 Standard X64 Edition
- Microsoft SQL Server 2005 Standard Edition for Itanium-based Systems
- Microsoft SQL Server 2005 Enterprise X64 Edition
- Microsoft SQL Server 2005 Enterprise Edition for Itanium-based Systems
- Microsoft SQL Server 2008 Developer
- Microsoft SQL Server 2008 Enterprise
- Microsoft SQL Server 2008 Standard
- Microsoft SQL Server 2008 Web
- Microsoft SQL Server 2008 Workgroup
| kbexpertiseadvanced kbsurveynew kbqfe kbfix KB975417 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate
|
 |
 |
 |
 |
 |
 |
 |
| |