ここで私はそれをやります。計画は、各結果セットを取得し、それをXMLに変換し、2つのXML結果を比較することです。はるかに簡単です(私の意見では)。
CREATE TABLE MyTable
(
[id] integer identity,
[Title] varchar(1024),
[Point] int,
[Date] datetime
);
insert into MyTable([Title], [Point], [Date])
values('T1', 1, '2012-04-26 07:14:34.000'),
('T1', 2, '2012-07-26 07:14:34.000'),
('T1', 3, '2012-06-26 07:14:34.000'),
('T1', 4, '2012-05-26 07:14:34.000'),
('T2', 1, '2012-04-26 07:14:34.000'),
('T2', 2, '2012-07-26 07:14:34.000'),
('T2', 3, '2012-06-26 07:14:34.000'),
('T2', 4, '2012-05-26 07:14:34.000'),
('T3', 4, '2012-05-26 07:14:34.000'),
('T3', 3, '2012-06-26 07:14:34.000'),
('T4', 1, '2012-04-26 07:14:34.000'),
('T4', 2, '2012-07-26 07:14:34.000'),
('T4', 3, '2012-06-26 07:14:34.000'),
('T4', 4, '2012-05-27 07:14:34.000'),
('T5', 2, '2012-12-27 07:14:34.000'),
('T5', 6, '2012-05-27 07:14:34.000'),
('T5', 3, '2012-07-26 07:14:34.000');
-- your original queries
Select Point, Date From MyTable Where Title = 'T1';
Select Point, Date From MyTable Where Title = 'T2';
-- first I am going to just get each one as XML
SELECT [Point], [Date]
FROM MyTable
WHERE Title = 'T1'
FOR XML PATH('');
SELECT [Point], [Date]
FROM MyTable
WHERE Title = 'T2'
FOR XML PATH('');
-- first just get the two results into one result set
select t.FirstCheck, t.SecondCheck
from (
select (SELECT [Point], [Date]
FROM MyTable
WHERE Title = 'T1'
FOR XML PATH('')) as FirstCheck,
(SELECT [Point], [Date]
FROM MyTable
WHERE Title = 'T2'
FOR XML PATH('')) as SecondCheck
) as t;
-- now for the real check.
declare @flag int;
select @flag = case when t.FirstCheck = t.SecondCheck then 1 else 0 end
from (
select (SELECT [Point], [Date]
FROM MyTable
WHERE Title = 'T1'
FOR XML PATH('')) as FirstCheck,
(SELECT [Point], [Date]
FROM MyTable
WHERE Title = 'T2'
FOR XML PATH('')) as SecondCheck
) as t;
-- this should return 1
select @flag as Flag;
select @flag = case when t.FirstCheck = t.SecondCheck then 1 else 0 end
from (
select (SELECT [Point], [Date]
FROM MyTable
WHERE Title = 'T1'
FOR XML PATH('')) as FirstCheck,
(SELECT [Point], [Date]
FROM MyTable
WHERE Title = 'T3'
FOR XML PATH('')) as SecondCheck
) as t;
-- this should return 0
select @flag as Flag;
私があなたがしようとしていることを理解していれば、これが必要です。
あなたはどんな出力を探していますか?どのようにクエリをフィルタリングしていますか? t4.4がt1.4、t2.4、t3.4と異なる日付を持つことを確認しますか?欠落しているt5.1とt5.4は重要です(逆にt1.6など)。/ countで単純なグループを指定すると、5つのタイトルがあることが分かっていればギャップを見つけるのに役立ちます。たった4ポイント1が26.4に出てくるのですが、例えば – u07ch