SQL procedure to diplay rows as column name and corresponding data

I have 4 tables  , in which Table 1, Table 2 and Table 3 are cofiguration tables where as Table 4 will have regular data entry

Please see attached spreadsheet for the table structure and desired results. Can you please help me with SQL procedure (SQL Server) to get the expected results.

Thanks for your help
QA.xlsx
hhqaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JestersGrindCommented:
First, I have to tell you that you have a design issue.  I see what you are trying to do and it's bad design.  It makes querying the data much harder and destroys data integrity.  You're mixing different values in the value column of table4 such that it makes it difficult to enforce different datatypes.  

The way to get the results that you want is to use PIVOT.  This should work.

SELECT * 
FROM (
	SELECT T3.Name, [Role], [Value]
	FROM #Table3 AS T INNER JOIN 
		#Table4 AS T2 ON T.SID = T2.SID INNER JOIN 
		#Table1 AS T3 ON T2.ID = T3.ID INNER JOIN 
		#Table2 AS T4 ON T.RoleID = T4.RoleID
	) AS s
PIVOT
(
 MAX(Value)
 FOR Name IN([FirstName], [LastName], [Email ID], [Phone])
)AS p

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2008

From novice to tech pro — start learning today.