user4579167
user4579167

Reputation: 1

SQL Server - Generate a NAME table by pulling data from StringId table

Here is the starting point:

"dbo.Person" Table

Id  | FirstNameStringId | LastNameStringId
.....  .................   ................
236 |     1234          |      5678

"StringCulture.dbo"

So this table defines the value of each StringId

   StringId | CultureCode | Value
   ........   ............  .....
      1234  | en-GB       | Bob
      5678  | en-GB       | Smith

This is what I need ...

Generate a table (exported to Excel) that shows

Id  | LastName | FirstName
...  ........   ..........
236 |  Bob     | Smith

Would appreciate some feedback as to the Procedure or Query I need to use to generate the table, and then export it.

Upvotes: 0

Views: 17

Answers (1)

Tony Hopkinson
Tony Hopkinson

Reputation: 20320

Just join to the Stringculture table twice using aliases.

Select p.id,fn.value,ln.value
From person p
inner join StringCulture fn on fn.stringid = p.FirstNameStringId
inner join StringCulture ln on ln.stringid = p.LastNameStringId

is the basic idea.

You'd have use outer joins if it was possible for a person not to have first or /and last name

Upvotes: 1

Related Questions