Jump to content
#StayAtHome ×
FooKelvin

MS SQL Join View Table. HELP

Recommended Posts

Hello,


 


I have a question regarding SQL. Please refer my attachment below:


post-179514-0-68351500-1445597103_thumb.jpg


 


Query 1:



SELECT dbo.[evaluation[Submit]]].FormID, dbo.empDB.Name, dbo.FormTbl.FormName, dbo.[evaluation[Submit]]].groupName, dbo.[evaluation[Submit]]].subGroup,
dbo.subgrouptbl.subgroupName
FROM dbo.[evaluation[Submit]]] INNER JOIN
dbo.empDB ON dbo.[evaluation[Submit]]].EmpID = dbo.empDB.EmployeeID INNER JOIN
dbo.FormTbl ON dbo.[evaluation[Submit]]].FormID = dbo.FormTbl.FormID INNER JOIN
dbo.subgrouptbl ON dbo.[evaluation[Submit]]].subGroup = dbo.subgrouptbl.subgroupID
WHERE (dbo.[evaluation[Submit]]].EmpID = '00001')

This view of table give me correct of the output. Which give me 36 of results. Please refer attachment below:


post-179514-0-40582600-1445597108_thumb.jpg


 


But, when i try to put additional table which i need to indicated whether the form is completed or draft, it's because i do not want to show "draft" form in the table.


 


Have a look on the table below:


post-179514-0-35599200-1445597110_thumb.jpg


 


After i added this table into my view, the output is repeated 2 times and give me 72 of results. 


Query 2:



SELECT dbo.[evaluation[Submit]]].FormID, dbo.empDB.Name, dbo.FormTbl.FormName, dbo.[evaluation[Submit]]].groupName, dbo.[evaluation[Submit]]].subGroup,
dbo.subgrouptbl.subgroupName, dbo.EmployeeDetails.submissionStatus
FROM dbo.[evaluation[Submit]]] INNER JOIN
dbo.empDB ON dbo.[evaluation[Submit]]].EmpID = dbo.empDB.EmployeeID INNER JOIN
dbo.FormTbl ON dbo.[evaluation[Submit]]].FormID = dbo.FormTbl.FormID INNER JOIN
dbo.subgrouptbl ON dbo.[evaluation[Submit]]].subGroup = dbo.subgrouptbl.subgroupID INNER JOIN
dbo.EmployeeDetails ON dbo.empDB.EmployeeID = dbo.EmployeeDetails.EmpID
WHERE (dbo.[evaluation[Submit]]].EmpID = '00001')

Share this post


Link to post
Share on other sites

Do you have more than one record for each employee in the EmployeeDetails table. You probably need to join on empid and formid

Share this post


Link to post
Share on other sites

Yes Barand. I have more than one record for each employee in EmployeeDetails table. I try to join like this and still give me repeated output.

post-179514-0-50619800-1445654832_thumb.jpg

 

 

Share this post


Link to post
Share on other sites

Hi Barand, i think i fixed my problem. I overlook, actually the form and employee id will repeat at each table. The only thing that unique is the subgroup. so i link it, i think the output is correct.

 

Thank You Barand.

Have a nice day! 

 

btw, how to close topic?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.