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 |
krish.vak
Starting Member
1 Post |
Posted - 2012-01-26 : 02:35:02
|
i have 2 tables invoice , repcomm which has the following structureinvoiceinvno invdate rep gtotal001 06/01/2011 kumar 5000002 08/01/2011 raj 2500003 05/05/2011 kumar 3000repcomrep rdate commPerkumar 01/01/2011 10kumar 01/05/2011 15raj 01/01/2011 5raj 01/05/2011 10the "repcom" table contains the percentage of commission which will be raised or lowered during the representative's service.while calculating the rep commission for a particular invoice i need to use a query that fetch the "commPer" from the table "repcom" with respect to the invdate in "invoice" table krish |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-01-26 : 09:04:01
|
quote: Originally posted by krish.vak i have 2 tables invoice , repcomm which has the following structureinvoiceinvno invdate rep gtotal001 06/01/2011 kumar 5000002 08/01/2011 raj 2500003 05/05/2011 kumar 3000repcomrep rdate commPerkumar 01/01/2011 10kumar 01/05/2011 15raj 01/01/2011 5raj 01/05/2011 10the "repcom" table contains the percentage of commission which will be raised or lowered during the representative's service.while calculating the rep commission for a particular invoice i need to use a query that fetch the "commPer" from the table "repcom" with respect to the invdate in "invoice" table krish
SELECT i.*,r.commPerFROM invoice iCROSS APPLY (SELECT TOP 1 commPer FROM repcom WHERE rep = i.rep AND rdate<=invdate ORDER BY rdate DESC)r ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
|
|
|
|
|