Hi Naomi, Thanks for the help too
As I told Sergey, the real query is different, I just simplified it to those queries as it is apparently the root of the problem. Running those queries yield the [unexpected?] result, which then is what I believe is the cause of the SP failing too. It makes no sense to me the results of the queries as posted, or I really need vacations.
>I think there is something else. It may be better to post the whole SP. I believe the last query is supposed to return records.
>
>The alternative and preferrable way (more performant) to write the last query is
>
>select E.PK from TVM.dbo.EventsLog E LEFT JOIN tvm.dbo.FaultsLog F ON E.PK =F.fkEventsLog where F.PK IS NULL
>
>>I have two tables EventsLog and FaultsLog, FaultsLog has a foreign key to EventsLog and I run this queries
>>
>>
>>select EventsLog.PK from TVM.dbo.EventsLog where PK = 1095387
>>
>>select FaultsLog.PK, FaultsLog.fkEventsLog from TVM.dbo.FaultsLog where FaultsLog.fkEventsLog = 1095387
>>
>>select EventsLog.PK from TVM.dbo.EventsLog where EventsLog.PK not in (select FaultsLog.fkEventsLog from tvm.dbo.FaultsLog)
>>
>>
>>First query returns one record, all is good.
>>Second query returns no records, still good.
>>Third query returns no records too?? Shouldn't I get the record for PK = 1095387?
>>
>>So confused...
>>
>>
>>(By the way, this is part of a longer store procedure that was working fine until Friday, today I noticed the problem and I think I narrowed it down to a query similar to this)
>>
>>
>>TIA,
>>
>>Hugo
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?
"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare
"To die for a religion is easier than to live it absolutely"
Jorge L. Borges