valeryk2000 (6/6/2014)
So ... order by does not work with intersect?
It works fine with intersect. Here is a full example to demonstrate it works just fine.
create table #tblLetterFlag
(
ClinicalReviewID int identity,
SomeValue varchar(10)
)
create table #tblClinicalReview
(
ClinicalReviewID int identity,
SomeValue varchar(10)
)
create table #tally(N int)
insert #tally
select N
from (values (1), (2), (3), (4), (5), (6), (7), (8), (9), (10)) dt(N)
insert #tblLetterFlag
select 'Value ' + CAST(N as varchar)
from #Tally
where N <= 10
insert #tblClinicalReview
select 'Value ' + CAST(N as varchar)
from #Tally
where N <= 5
select ClinicalReviewID from #tblLetterFlag
except
select ClinicalReviewID from #tblClinicalReview
order by ClinicalReviewID
select ClinicalReviewID from #tblLetterFlag
intersect
select ClinicalReviewID from #tblClinicalReview
order by ClinicalReviewID
drop table #tblLetterFlag
drop table #tblClinicalReview
drop table #tally
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/