SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 query help
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

krish.vak
Starting Member

1 Posts

Posted - 01/26/2012 :  02:35:02  Show Profile  Reply with Quote
i have 2 tables invoice , repcomm which has the following structure

invoice
invno invdate rep gtotal
001 06/01/2011 kumar 5000
002 08/01/2011 raj 2500
003 05/05/2011 kumar 3000


repcom
rep rdate commPer
kumar 01/01/2011 10
kumar 01/05/2011 15
raj 01/01/2011 5
raj 01/05/2011 10



the "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

India
52325 Posts

Posted - 01/26/2012 :  09:04:01  Show Profile  Reply with Quote
quote:
Originally posted by krish.vak

i have 2 tables invoice , repcomm which has the following structure

invoice
invno invdate rep gtotal
001 06/01/2011 kumar 5000
002 08/01/2011 raj 2500
003 05/05/2011 kumar 3000


repcom
rep rdate commPer
kumar 01/01/2011 10
kumar 01/05/2011 15
raj 01/01/2011 5
raj 01/05/2011 10



the "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.commPer
FROM invoice i
CROSS APPLY (SELECT TOP 1 commPer
             FROM repcom
             WHERE rep = i.rep
             AND rdate<=invdate
             ORDER BY rdate DESC)r


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

Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000