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
 Link files by date and time

Author  Topic 

geyes
Starting Member

1 Post

Posted - 2012-04-19 : 13:38:37
I have two files:

1)Invoice file
2)Cost file

I would like to create an output file/report called margin report.

I want to link the sales to find the cost for the order. It is based on date and time.

See example below for the output. What is the best SQl script for this?


Invoice file

Order1 Item1 Sales1 Date1 Time1
1001 A1001 10.00 04/15/12 151025
1002 A1001 12.00 04/15/12 151112
1003 A1001 11.00 04/15/12 171235
1004 A1001 14.00 04/15/12 171543
1005 A1001 13.50 04/15/12 171855



Cost file

Item2 Cost2 Date2 Time2
A1001 3.50 04/14/12 171255
A1001 4.20 04/15/12 151233
A1001 2.50 04/15/12 171523
A1001 4.00 04/15/12 171623


Output file - Margin report

Order Item Sales Cost Margin
1001 A1001 10.00 3.50 6.50
1002 A1001 12.00 3.50 8.50
1003 A1001 11.00 2.50 8.50
1004 A1001 14.00 2.50 11.50
1005 A1001 13.50 4.00 9.50


sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-04-19 : 14:08:46
What is the rule you are using to associate a row in the invoice file with a row in the cost file?

a) Row that has the closes date&time in cost file?
b) Row that has the closest date&time in the cost file that is earlier than the date&time in the Invoice file?
c) Something else? Seemed to me like it is something else.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-04-19 : 14:15:15
Cant make out any relationship by which you're getting the result. how do you determine which cost need to applied for a sales? some cases you're taking cost having effective datetime after the sales, why is it so?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -