I have a bill table with following detailClient, bill_date,bill_amount, branch ...I need to fetch data for top 5 client from every branch below query gives me the data across for A branch Code: SELECT TOP 5 * FROM (Select Client_id, branch , sum(bill_amount)amountfrom dbo.billtablewhere trade_date >= '01 oct 2009' and trade_date CODE]for all the branches i dont want to hard code the branch value as there are around 900 branchesthere is one more table which contain branch names, for do while loop to take branch name as a variable for extraction , I need to write a function can someone please suggest how to write function in SQL 2000please help
Welcome to the forum! Although in German, you should be able to understand the code here: http://www.insidesql.org/beitraege/entwicklung/n-datensaetze-pro-gruppierung-anzeigen