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 2005 Forums
 Transact-SQL (2005)
 Outer join

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2007-03-12 : 09:25:05
Judy writes "I have created a table and do not want the matching records of the created table in the results.

SELECT PONUMBER, POPRCTNM
INTO ##USETAX
FROM POP10500
WHERE DateRECD between '2007-02-01' and '2007-02-28'
AND
ITEMNMBR like '%TAX%'

But my results give me the matching records.
When I run the query on the first table where the date range is between I get 1061 records

Select * from Pop10500 where DateRECD between '2007-02-01' and '2007-02-28'

When I run the second query with the join I get 754 records (Records which match the second table)

Select a.PONUMBER, a.POPRCTNM, a.ITEMNMBR, a.vendorid, a.orcptcost
from Pop10500 a JOin ##USETAX b on a.PONUMBER = b.PONUMBER
AND a.POPRCTNM = b.POPRCTNM
where a.DateRECD between '2007-02-01' and '2007-02-28'
order by a.PONUMBER

So, I want the results to be 303 records "

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-03-12 : 10:11:13
[code]Select
a.PONUMBER, a.POPRCTNM, a.ITEMNMBR, a.vendorid, a.orcptcost
from
Pop10500 a LEFT JOin ##USETAX b
on
a.PONUMBER = b.PONUMBER
AND a.POPRCTNM = b.POPRCTNM
where
a.DateRECD between '2007-02-01' and '2007-02-28'
and b.PONUMBER IS NULL and b.POPRCTNM IS NULL
order by
a.PONUMBER
[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

JudyV
Starting Member

1 Post

Posted - 2007-03-14 : 15:59:55
Thank you for your help. Guess, I was having a brain burp.
Go to Top of Page
   

- Advertisement -