Re: Pulling data that could be in one of 2 tables
- From: Hugo Kornelis <hugo@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 27 Oct 2007 00:21:13 +0200
On Fri, 26 Oct 2007 09:40:00 -0700, Matt M wrote:
(snip)
Probably not the most efficient way to do it but it got the job done and my
numbers came out exact.
Hi Matt,
This way is probably more efficient:
SELECT Main.SOPTYPE, Main.SOPNUMBE, Main.ORIGNUMB,
Main.DOCID, Main.DOCDATE, Main.INVODATE,
Main.MSTRNUMB, Main.DOCAMNT,
COALESCE(Original.DOCID, History.DOCID) AS ORIGDOCID
FROM SOP30200 AS Main
LEFT JOIN SOP10100 AS Original
ON Original.SOPNUMBE = Main.ORIGNUMB
LEFT JOIN SOP30200 AS History
ON History.SOPNUMBE = Main.ORIGNUMB
AND AND History.SOPTYPE = '2'
WHERE Main.SOPTYPE = '3'
AND Main.DOCDATE >= @BeginDate
AND Main.DOCDATE <= @EndDate;
(untested)
--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
.
- References:
- Re: Pulling data that could be in one of 2 tables
- From: Russell Fields
- Re: Pulling data that could be in one of 2 tables
- From: Matt M
- Re: Pulling data that could be in one of 2 tables
- From: Russell Fields
- Re: Pulling data that could be in one of 2 tables
- From: Matt M
- Re: Pulling data that could be in one of 2 tables
- From: Hugo Kornelis
- Re: Pulling data that could be in one of 2 tables
- From: Matt M
- Re: Pulling data that could be in one of 2 tables
- Prev by Date: Re: Pulling data that could be in one of 2 tables
- Next by Date: Table Query
- Previous by thread: Re: Pulling data that could be in one of 2 tables
- Next by thread: Re: Pulling data that could be in one of 2 tables
- Index(es):
Relevant Pages
|
|