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
 delete

Author  Topic 

mcupryk
Yak Posting Veteran

91 Posts

Posted - 2011-03-22 : 14:57:19
delete

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2011-03-22 : 15:00:58
You would need to create separate queries for each, similar to this:

SELECT U.* FROM Unions U WHERE U.UnionID = 1
SELECT E.* FROM Employees E INNER JOIN Unions U ON E.UnionID = U.UnionID WHERE UnionID = 1
SELECT C.* FROM Contracts C INNER JOIN Employees E ON E.EmployeeID = C.EmployeeID INNER JOIN Unions U ON E.UnionID = U.UnionID WHERE UnionID = 1

(the table names and join criteria are not the same as your data but hopefully you get the idea)

cheers,

Tim
Go to Top of Page

MIK_2008
Master Smack Fu Yak Hacker

1054 Posts

Posted - 2011-03-22 : 15:18:45
May be it would only be me who is unable to understand your requirements. Perhaps it would be helpful if you comeup with 1) sample data for all your tables. 2) PK and FKs of the tables 3) the required output or the desired operation should be done

Cheers
MIK
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-03-22 : 15:37:41
Better to script out the tables involved and post the CREATE TABLE statements for them.
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-03-23 : 10:15:21
That's a big help, although it's missing the definition for tblLabourFiles. Do you have any foreign keys defined between these tables? The script for those would help too.

Looking back on your original query, I noticed a number of join conditions were not specified (tblLabourFiles to employees somehow, tblLabourFilesUnion to tblUnionNames). You also have a number of tables listed that you don't extract data from, and aren't necessary to answer the query as I read it (e.g. tblReasons).

Also, you describe this as a "union" but what you've written is not a UNION in SQL terms. You're joining all these tables together and extracting different columns from each. Is that your intention?
Go to Top of Page

mcupryk
Yak Posting Veteran

91 Posts

Posted - 2013-06-08 : 00:23:47
quote:
Originally posted by timmy

Y

Tim



Any help would be awesome.
Go to Top of Page
   

- Advertisement -