FIX: ???? ????? SELECT ??????? ??? ???? ??? ??? ???? ????? ??????? ?? SQL Server 2005 ?? ?? SQL Server 2008

?????? ????????? ?????? ?????????
???? ???????: 975417 - ??? ???????? ???? ????? ????? ??? ???????.
Microsoft ?????? ????????? Microsoft SQL Server 2005 ???? ???? ??????? ???????. ??? ????????? ???????? ????? ?? ????? ???? ???? ????????? ??????? ????? ???? ??????? ?????? ???? ?? ??????? ?? SQL Server 2005 ??????? ???????.Microsoft ?????? ????????? Microsoft SQL Server 2008 ???? ???? ??????? ???????. ??? ????????? ???????? ????? ?? ????? ???? ???? ????????? ??????? ????? ???? ??????? ?????? ???? ?? ??????? ?? SQL Server 2008 ??????? ???????.
????? ???? | ?? ????

?? ??? ??????

???????

?? Microsoft SQL Server 2005 ?? ?? Microsoft SQL Server 2008 ?????? ????? SELECT ??? ??????? ???? ?????? ???? ????? ????? ?????? ?? ????? ??????? ??? ?????.

????

SQL Server 2005 ?????? ????? ?????? Service Pack 3

?? ????? ??????? ????? ???? ??????? ????? ?? ??????? ???????? 6 ????? SQL Server 2005 ?????? ????? ?????? Service Pack 3. ????? ?? ????????? ??? ???? ??????? ???????? ??? ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
974648???? ??????? ???????? 6 SQL Server 2005 ?????? ????? ?????? Service Pack 3
?????? ??? ????????? ???????? ????? ?? ????? ????? ???? ???? ????????? ??????? ????? ???? ??????? ?????? ???? ?? ??????? ?? SQL Server 2005 ??????? ???????. ???? Microsoft ?????? ????? ???? ????? ??????? ???? ????? ??? ??? ??????? ??????. ????? ?? ?????????? ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
960598???? SQL Server 2005 ???? ?? ??????? ??? ????? SQL Server 2005 ?????? ????? ?????? Service Pack 3
Microsoft SQL Server 2005 ??? ????? ????????? ??????? ??? ???? SQL Server ?????. ??? ????? ??????? ???? SQL Server 2005 ?????? ????? ?????? Service Pack 3 ??? ????? SQL Server 2005 ?????? ????? ?????? Service Pack 3. ???? ???????? ??? ????? ????????? ??????? ???????? ?? ???? ???? ?? SQL Server ?? ???? ???? ?? SQL Server ???????.

???? ????? SQL Server 2008

??? ??? ????? ??? ??????? ??? ??? ?????? ???? ????? SQL Server 2008.

?? ????? ??????? ????? ???? ??????? ????? ?? 8 ??????? ????????. ????? ?? ????????? ??? ????? ?????? ??? ???? ??????? ???????? ??? ?? SQL Server 2008 ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
975976???? ??????? ???????? 8 SQL Server 2008
?????? ??? ????????? ???????? ????? ?? ????? ????? ???? ???? ????????? ??????? ????? ???? ??????? ?????? ???? ?? ??????? ?? SQL Server 2008 ??????? ???????. ???? ???? ???????? ????? ???? ????? ??????? ???? ????? ??? ??? ??????? ??????. ????? ?? ?????????? ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
956909???? SQL Server 2008 ???? ?? ??????? ??? ????? SQL Server 2008

SQL Server 2008 ?????? ????? ?????? Service Pack 1

??? ??? ????? ??? ??????? ??? ??? ?????? SQL Server 2008 ?????? ????? ?????? Service Pack 1.

?? ????? ??????? ????? ???? ??????? ????? ?? ??????? ???????? 5 ?? SQL Server 2008 ?????? ????? ?????? Service Pack 1. ????? ?? ????????? ??? ???? ??????? ???????? ??? ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
975977???? ??????? ???????? 5 SQL Server 2008 ?????? ????? ?????? Service Pack 1
?????? ??? ????????? ???????? ????? ?? ????? ????? ???? ???? ????????? ??????? ????? ???? ??????? ?????? ???? ?? ??????? ?? SQL Server 2008 ??????? ???????. ???? Microsoft ?????? ????? ???? ????? ??????? ???? ????? ??? ??? ??????? ??????. ????? ?? ?????????? ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
970365???? SQL Server 2008 ???? ?? ??????? ??? ????? SQL Server 2008 ?????? ????? ?????? Service Pack 1
Microsoft SQL Server 2008 ??? ????? ????????? ??????? ??? ???? SQL Server ?????. ??? ????? ??????? ???? SQL Server 2008 ?????? ????? ?????? Service Pack 1 ??? ????? SQL Server 2008 ?????? ????? ?????? Service Pack 1. ???? ???????? ??? ????? ????????? ??????? ???????? ?? ???? ???? ?? SQL Server ?? ???? ???? ?? SQL Server ???????.

?????

???? Microsoft ?? ??? ????? ?? ?????? Microsoft ??????? ?? ??? "????? ???".

??????? ????

????? ????? ????? ???????

The 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
*/

?????

????? ?? ????????? ??? "????? ????? ??????" ?? SQL Server ? ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
935897????? "????? ????? ??????" ?? ???? SQL Server ?????? ????????? ??????? ??????? ?? ??????? ????
????? ?? ????????? ??? ????? ?????? ??? SQL Server 2005 ?????? ????? ?????? Service Pack 3 ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
913089????? ?????? ??? ???? ???? ???? ?? SQL Server 2005
?????? ??? ???? ?? ????????? ??? ??????? ??????? ?? SQL Server 2005 ?????? ????? ?????? Service Pack 3 (SP3) ?????? ??? ????????? ???????? ?? SQL Server 2005 SP3 ?? ?????? ???? Microsoft ?????? ??? ?????:
http://go.microsoft.com/fwlink/?LinkId=131442
????? ?? ????????? ??? ???? ??????? ???????? SQL Server ? ???? ??? ??? ??????? ?????? ?????? ?? "????? ??????? ?? Microsoft:
822499???? ????? ????? ??? ??????? ????? Microsoft SQL Server
????? ?? ????????? ??? ??????? ????? ??????? "? ???? ??? ??? ??????? ?????? ?????? ??" ????? ??????? ?? Microsoft:
824684??? ????????? ???????? ????????? ?? ??? ??????? ????? Microsoft

???????

???? ???????: 975417 - ????? ??? ??????: 30/????/1430 - ??????: 1.1
????? ???
  • 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
????? ??????: 
kbmt kbexpertiseadvanced kbsurveynew kbqfe kbfix KB975417 KbMtar
????? ????
???: ??? ????? ??? ?????? ???????? ?????? ????? ???? ????? ?????????? ????? ?? ????????? ?????? ????. ???? ???? ?????????? ???? ?? ???????? ???????? ?????? ????????? ????? ????????? ???????? ????? ???????? ?????? ?? ?????? ??? ?? ???????? ???????? ?? ????? ??????? ?????? ??? ??????? ?????? ??. ?????? ?? ???? ??? ??????? ???????? ????? ?? ???? ????? ?????? ??? ????? ??? ????? ??????? ?? ????? ?? ?????? ??? ??? ??????? ??????? ?? ????? ????? ????? ????? ?????. ?? ????? ???? ?????????? ??????? ??? ????? ?? ??????? ?? ????? ?????? ?? ??? ????? ?? ????? ??????? ?? ???????? ?? ??? ???????. ???? ???? ?????????? ???????? ??? ????? ?????? ??????? ??????
???? ??? ????? ??????? ?????? ??????????975417

????? ???????

 

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from smallbusiness.support.microsoft.com