I came across a select statement that has me all ! There is a
reference to a table in a case clause which does not appear anywhere else in
the Select. In the example below, TableC is a regular database table which
does not appear in the From or the where or anywhere else. I had no idea
this can be done and I have no idea what it is really doing. Any suggestions
?
Perplexed!
Select
.
.
CASE WHEN TableC.SaleDate IS NOT NULL THEN 1 ELSE 0 END 'IsSold',
. .
From tableA, tableB
Where . . .Could you post a complete query rather than a fragment? DDL might help
too.
You can't reference a table name / alias unless A) that name is
included in a FROM / JOIN clause in the same query / subquery OR B) the
name Exists in an outer part of the query and is referenced in a
subquery. I can't think of any exceptions.
David Portas
SQL Server MVP
--
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment