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 |
|
nerdygirl61
Starting Member
21 Posts |
Posted - 2011-12-20 : 14:22:21
|
| I am trying to figure out the best way to do this, there is a simplified sample of the data below.For the records in the MainFile I need to find the corresponding MasterStaff record using the CEID and PayPeriod, and create a record for each FRN/AllocPCT. I am not sure of the best way to do this. There are more fields and tables involved, but those will be easy once I get the bones figured out. I thought about using a WHILE but haven’t done that in SQL, and didn’t know if I should use a count or check to see if the allocPct is 0. I thought about doing a CASE and passing the parameters to a function and adding to the table using a function, I’m assuming I don’t have to return a value(?). Any input would be appreciated.MainFileCEID PayPeriod Dollars1111 201112 25.001112 201112 250.001113 201112 50.00MasterStaffCEID PayPeriod FRN1 AllocPct1 FRN2 AllocPct2 FRN3 AllocPct31111 201112 3313 0.75 3312 0.25 NULL 0.001112 201112 3313 0.50 4400 0.25 4413 0.251113 201112 4413 100.00 NULL 0.00 NULL 0.00ReportFile (Output)CEID PayPeriod FRN1 ProRateDollars1111 201112 3313 18.751111 201112 3312 6.251112 201112 3313 125.001112 201112 4400 62.501112 201112 4413 62.501113 201112 4413 50.00 |
|
|
toddbkc
Starting Member
9 Posts |
Posted - 2011-12-20 : 14:59:31
|
| I would try using a UNION ALL statement, like this:/* FRN1 populated */select CEID,PayPeriod,FRN1,AllocPct1from MainFileINNER JOIN MasterStaff...UNION ALLselect CEID,PayPeriod,FRN2,AllocPct2from MainFileINNER JOIN MasterStaffwhere masterstaff.FRN2 IS NOT NULL...UNION ALLselect CEID,PayPeriod,FRN3,AllocPct3from MainFileINNER JOIN MasterStaffwhere masterstaff.FRN3 IS NOT NULLDoes this help?TODD |
 |
|
|
nerdygirl61
Starting Member
21 Posts |
Posted - 2011-12-20 : 17:23:29
|
Yes it does! You are awesome, thank you, Karen |
 |
|
|
|
|
|
|
|