I have a table tbl_Info:
InfoId
Text
PrivacyTypeId
UserName
TypeId
IsInfo
InfoItemId
Example of data:
1|Some text...|1|userX|1|False|NULL
2|New job created|1|system|3|True|765
3|Image commented|1|system|4|True|457
In my application I get all values from this table and I display them as a list.
Application users can click on each of this items and they should be redirected somewhere in application.
I have a few tables in database that is bound for this table but this connection is very dynamic. For example this tables:
tbl_Jobs{JobId, Title etc.}, tbl_Articles{ArticleId, Title etc.}
Here is the problem:
Before I added IsInfo and InfoItemId I have only one type where users enter this infos and all I need is to get info columns + user full name:
select i.*, p.FirstName + ' ' + p.LastName as Author
from tbl_Info i
left join tbl_Profiles p on i.UserName = p.UserName
where i.PrivacyTypeId = 1
Now I need to change this Author column with name of Title and this values should be: Full name or Job Title or Article Title etc.
I don’t know is it possible to make select procedure so it can based on IsInfo and TypeId get item title from another table with ID of InfoItemId.
So something like: If IsInfo = True. Get typeId. And based on this typeId join to some table and get some column from it.
IF typeId = 2 ... join tbl_Jobs on ...
IF typeId = 3 ... join tbl_Articles on ...
I’m sorry for a little longer post. But I can’t find solution for this and I need to explain problem in a little more detail.
you could do something like this: