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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 join

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2007-06-05 : 05:00:25
How can i modify my sql query to retrieve the records in table h which are not present in table f ?

select
h.LimCodeFieldID,
h.FixingDate,
h.FixingValue,
h.CreatedDate,
h.CreatedUser
from
tblLimCodesFixingsDailyHistory h
inner join tblLimCodesFixings f on
(h.LimCodeFieldID = f.LimCodeFieldID) and
(h.FixingDate = f.FixingDate)

Kristen
Test

22859 Posts

Posted - 2007-06-05 : 05:02:47
Like this??

from
tblLimCodesFixingsDailyHistory h
LEFT OUTER join tblLimCodesFixings f on
(h.LimCodeFieldID = f.LimCodeFieldID) and
(h.FixingDate = f.FixingDate)
WHERE f.LimCodeFieldID IS NULL

Kristen
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2007-06-05 : 05:06:52
quote:
Originally posted by Kristen

Like this??

from
tblLimCodesFixingsDailyHistory h
LEFT OUTER join tblLimCodesFixings f on
(h.LimCodeFieldID = f.LimCodeFieldID) and
(h.FixingDate = f.FixingDate)
WHERE f.LimCodeFieldID IS NULL

Kristen


many thanks
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-06-05 : 09:33:15
You can also use not exists

select
h.LimCodeFieldID,
h.FixingDate,
h.FixingValue,
h.CreatedDate,
h.CreatedUser
from
tblLimCodesFixingsDailyHistory h
where not exists(select * from f where LimCodeFieldID = h.LimCodeFieldID and FixingDate = h.FixingDate)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -