[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 446
  • Last Modified:

SQL Join Query Help

I have a Training_Tasks table that looks like this:
ID  TaskDept   TaskName
01  Eng            JobPrep
02  Eng            JobCheck
03  Mill           BeamSaw
04  Mill           Cutting

and an Employee table that looks like this:
ID  Dept  Name
01  Eng    Mike
02  Eng    Paul
03  Mill    John

and the table to store my data for Task Training Hours looks like this:

ID  EmpID  TaskID   TotalHours   TrainingDate
01  01         01          1.5                  1/1/2013
02  01         04           6.5                 1/1/2013
03  02         02           8.0                  1/1/2013

... and so on...

I need a view the above table and see my Task Training Hours represented this way:
(see task name)

EmpDept   Employee     TaskDept   JobPrep     JobCheck    Cutting     TrainingDate
Eng            Mike                  Eng           1.5                                               1/1/2013
Eng            Mike                  Mill                                              6.5            1/1/2013
Eng            Paul                   Eng                             8.0                              1/1/2013


Basically I want a column split out per TaskName and the view needs to be editable.

Thank you for your help!
0
Bianca
Asked:
Bianca
1 Solution
 
plusone3055Commented:
interesting puzzle there
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
That would be a PIVOT, where rows are rows, data in one column becomes the columns on the return set, and the 'cell' intersect is an aggregate like SUM() or Count().

Click on the below link, and scroll down, for decent examples.
http://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx
0
 
Ramdasa MayyaCommented:
You can use crosstab
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
BiancaAuthor Commented:
I need the SQL view reflected that way. SQL Query...
0
 
SharathData EngineerCommented:
You have 7 columns in the expected result but the expected result has 5 columns of data only. How exactly you want the result set?
0
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now