[thelist] T-SQL join I can't grok
Matt Warden
mwarden at gmail.com
Mon Nov 21 18:15:51 CST 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Canfield, Joel wrote:
> (specifically MSSQL in case it matters)
>
> I have four tables to join in order to get a human-readable list. Here's
> pseudo-code for what I'm looking for:
>
> select d.document_number, p.permissions,
> [here's the tricky part]
> (either u.fullname or g.fullname,
> depending on whether p.object_type is 'g' or 'u')
> from (lotsa joined tables; I can write the joins)
>
> I just can't get my head around the logic to decide which table to query
> depending on the value of p.object_type for each row returned.
select (case p.object_type when 'g' then g.fullname when 'u' then
u.fullname else NULL END) as fullname
from lotsa l, joined u, tables g
where joelcanwritethejoins=1;
- --
Matt Warden
Miami University
Oxford, OH, USA
http://mattwarden.com
This email proudly and graciously contributes to entropy.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFDgmM3rI3LObhzHRMRAi0XAJwIjAjXnCiYqMmOJx3Q58D3hdAAXgCfV152
jjOu0i0u7RGwkSKu8dc0hHU=
=B/C4
-----END PGP SIGNATURE-----
More information about the thelist
mailing list