Cartesius00
Cartesius00

Reputation: 24384

SQL View without references

We have in SQL Server 2008 R2 a table T with 20 columns. Four columns are simple foreign keys from four other fixed (ID, Value) tables.

All we want now, is to create a new VIEW with those four foreign-key-columns of T replaced by those corresponding Values. 16 remaining columns should be untouched.

Please, how to achieve that in SQL in the most elegant way?

Upvotes: 0

Views: 49

Answers (1)

Alex K.
Alex K.

Reputation: 175866

Simply join the 4 related tables there isn't a shorthand way of doing it;

SELECT
  T1.Value as T1Value,
  ...
  T4.Value as T4Value,
  T.fld1
  ..
  T.fld16
FROM
  T
INNER JOIN T1 ON T.T1_ID = T1.ID
...
INNER JOIN T4 ON T.T4_ID = T4.ID

Upvotes: 2

Related Questions