Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Query from Two Tables

Author  Topic 

rangeshram
Starting Member

1 Post

Posted - 2011-11-07 : 02:02:05
Dear All,

I am newly registered user and also fresh to SQL Programming. We will happy if you provide any help/suggest for the below scenario.

We need to select the particular column in tblBenchmark where the column was available in tblProjectDetails

We have complexity levels based on the particular project
tblBenchmark
ProjectID Low Medium High
1 50 40 30
2 60 40 20

tblProjectDetails
ProjectID ProjectName Complexity
1 Pipeline Low
2 Standard Medium

From the above we need to get the result as below:
ProjectName Complexity Value
Pipeline Low 50
Standard Medium 40

Hope this clarifies. Let me know if you need any more details.

Thanks,

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-07 : 03:56:56
[code]
SELECT pd.ProjectName,pd.Complexity,m.[Value]
FROM
(
SELECT ProjectID,Complexity,[Value]
FROM tblBenchmark b
UNPIVOT([Value] FOR [Complexity] IN ([Low],[Medium],[High]))u
)m
INNER JOIN tblProjectDetails pd
ON pd.Project_ID = m.Project_ID
AND pd.Complexity = m.Complexity
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -