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.
Author |
Topic |
cal_bonjovi
Starting Member
3 Posts |
Posted - 2010-12-20 : 02:35:36
|
i need to have a query, i will use this in my reportpls consider the followingI have three tablesONEPersonnelID | WageType | Amount | Amortization | Start | End | Paydate | PayType123 Cash Loan 12000 1000 1/21/2010 12/21/2010 1/21/2010 M123 Cash Loan 800 200 3/21/2010 6/21/2010 3/21/2010 MTWOWageType | Descriptions7000 Cash Loan8000 Car LoanTHREEPersonnelID | WageType | PayDate 123 Cash Loan 5/21/2010 Sample1:-- wagetype field comes from the second table so an inner join can do this@Start = 1/21/2010@PayType = M@End = 2/21/2010RESULT TABLEPersonnelID | WageType | Start | End | Amount123 7000 1/21/2010 12/21/2010 1000Sample2:-- record one and two add Amount field because they have same personnelID, wageType and PayType-- End field become 12/31/9999 because a combination of two or more records happened@Start = 3/21/2010@PayType = M@End = 4/21/2010RESULT TABLEPersonnelID | WageType | Start | End | Amount123 7000 3/21/2010 12/31/9999 1200Sample3:-- no output for this one because table THREE stops it from happenning, coz a record in table THREE matchwith table ONE( one.personnelID = three.personnelID, one.wageType = three.wagetype, three.Paydate is between one.start and one.end)@Start = 5/21/2010@PayType = M@End = 6/21/2010RESULT TABLEPersonnelID | WageType | Start | End | Amount--no outputSample4:-- same explanations with sample3@Start = 7/21/2010@PayType = M@End = 8/21/2010RESULT TABLEPersonnelID | WageType | Start | End | Amount--no outputu can use this create querycreate database payrollGouse payrollcreate table ONE (PersonnelId int, Wagetype nvarchar(40), Amount int, Amortization int,start dateTime, enddate datetime, Paydate datetime, payType nvarchar(40))GOinsert into ONE values (123, 'Cash Loan', 12000, 1000, '1/21/2010', '12/21/2010', '1/21/2010', 'M')insert into ONE values (123, 'Cash Loan', 800, 200, '3/21/2010', '6/21/2010', '3/21/2010', 'M')GOcreate table TWO (WageType int, Descriptions nvarchar(40))GOinsert into TWO values (7000, 'Cash Loan')insert into TWO values (8000, 'Car Loan')GOcreate table THREE (PersonnelID int, WageType nvarchar(40), PayDate datetime)GOinsert into THREE values (123, 'Cash Loan', '5/21/2010')GOselect * from ONEselect * from TWOselect * from THREE |
|
|
|
|
|
|