Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hello,My question is about query I realy can't generate (If this is not the place, sorry...)I have two rables: Table1 with fiekds: F1, F2, F3 and table2 with fields F1, F2, F3. I would like to have all the records that are equal in their F1 and F2 fields, and are differnt in their F3 field, comarison the two tables.In a schematic way:table1.F1=table2.F1and table1.F2=table2.F2and table1.F3 <> table2.F3With these three condition in "Where", it does not work.I know it seems easy, but I can't do it...I'll appreciate any help with thatThanks!
webfred
Master Smack Fu Yak Hacker
8781 Posts
Posted - 2010-10-17 : 07:14:18
But it works:
declare @table1 table ( F1 int, F2 int, F3 int)declare @table2 table ( F1 int, F2 int, F3 int)insert @table1select 1,1,1 union allselect 2,2,2 union allselect 3,3,3insert @table2select 1,1,1 union allselect 2,2,2 union allselect 3,3,4select * from @table1 t1join @table2 t2 on t2.F1 = t1.F1 and t2.F2 = t1.F2 and t2.F3 <> t1.F3
No, you're never too old to Yak'n'Roll if you're too young to die.
anat
Starting Member
3 Posts
Posted - 2010-10-17 : 07:55:16
Thanks for answering me :-))But unfortunatly it doesn't work. One record in the output contains the same F3 fields (which supposed to be the different one).Any other suggestions?Thanks!
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2010-10-17 : 09:11:50
nope. in that case there might be something different between them, may be some unprintable characters like space, carriage return etc------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/
anat
Starting Member
3 Posts
Posted - 2010-10-18 : 07:23:13
yes, you are right!There was 'enter': chr(10) and chr(13) which I replaced.Thanks againAnat
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2010-10-19 : 13:16:48
Cool ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/