Re: Join to one of two tables (based on a value in the source table)

From: Joe Celko (jcelko212_at_earthlink.net)
Date: 08/23/04


Date: Mon, 23 Aug 2004 08:34:37 -0700


>> .. bit .. uniqueidentifier .. table1 and table2 do not have the same
structure .. fields .. I want to do a select from tableSource, that will
join to table1 or table2 .. depending on whether chooseTable is 0 or 1
. VARCHAR(50). <<

Okay, you want to use an assembly language level bit construct to give
yourself a query that returns apples or octopi.

Have you asked yourself just what this kind of query would mean in a
data model? If it is meaningful, then this attribute is split over two
tables and you have some serious design problems. If it is not
meaningful, then you have some serious programming problems.

Since you mention having a uniqueidentifier and VARCHAR(50) columns,
this looks like an ACCESS port in which no redesign work was done.
While it is possible that something is really VARCHAR(50), 80-90% of the
time I find this is the quickie kludge of a newbie, so my warnign light
goes on.

What are you trying to do? You have told us HOW you want to do it.
Where is the DDL?

--CELKO--
 ===========================
 Please post DDL, so that people do not have to guess what the keys,
constraints, Declarative Referential Integrity, datatypes, etc. in your
schema are.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Relevant Pages

  • Re: Complex aggregate query
    ... Your real problem is not understanding that columns are not fields, ... display the data in the query result. ... Please post DDL, so that people do not have to guess what the keys, ...
    (microsoft.public.sqlserver.programming)
  • Re: SQL query help
    ... Check out http://www.aspfaq.com/etiquette.asp?id=5006 on how to post DDL ... and example data for your tables, along with the expected output from your ... I have a table with products and closing dates for each of 4 quarters ... I need a query that will look at earning_dates and return the latest 6 ...
    (comp.databases.ms-sqlserver)
  • Re: TSQL Question. URGENT Help. Exists and Not Exists Question
    ... Can you post DDL for your actual table, including all constraints and ... And also post what indexthe query is using? ... SQL Server MVP ...
    (microsoft.public.sqlserver.programming)
  • MSSQL 2000 - Table locking, row locking, ...
    ... I'll post DDL and the data at the end of the post. ... Now, for the purpose of the auto-fifo stock prices, this query gives me ... I need to have locks on that table, so I'm sure that noone else tries to ...
    (microsoft.public.sqlserver.programming)

Loading