Re: Pulling data that could be in one of 2 tables
- From: Hugo Kornelis <hugo@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 25 Oct 2007 21:56:26 +0200
On Thu, 25 Oct 2007 07:30:01 -0700, Matt M wrote:
(snip)
Does this help? Your sample query you showed me looks promising but it may
take me a little bit to wrap my brain around it.
Hi Matt,
The main reason that this query is ntroublesome to come up with, is that
the design is bad. I'm not sure if you are able to change that (never
worked with GP, and after seeing their table and column names, I hope to
keep it that way). An order should be in the same table, whether it's
partially or fully shipped, or not shipped at all.
Anyway, if you are stuck with the design, than try sometinh like this:
SELECT base.SOPTYPE, base.SOPNUMBE, base.ORIGNUMB,
COALESCE(orig1.SOPTYPE, orig2.SOPTYPE),
COALESCE(orig1.SOPNUMBE, orig2.SOPNUMBE)
FROM table2 AS base
LEFT JOIN table1 AS orig1
ON orig1.SOPNUMBE = base.ORIGNUMBE
LEFT JOIN table2 AS orig2
ON orig2.SOPNUMBE = base.ORIGNUMBE
WHERE base.SOPTYPE = 3; -- Invoices only
(Untested - see www.aspfaq.com/5006 if you prefer a tested reply)
--
Hugo Kornelis, SQL Server MVP
My SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
.
- Follow-Ups:
- 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
- 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
- Prev by Date: Re: Pulling data that could be in one of 2 tables
- Next by Date: Re: Select Formatted Text From Table
- 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
|
|