Hi
i want to write a cursor where in branch name should be passed into the cursor one by one, I have a bill table with following detail
Client, 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 branch A
for all the branches i dont want to hard code the branch value as there are around 900 braches
there is one more table which contain branch names, if do while loop can take branch name as a variable
please help
i want to write a cursor where in branch name should be passed into the cursor one by one, I have a bill table with following detail
Client, 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 branch A
Code:
SELECT TOP 5 * FROM (Select Client_id, branch , sum(bill_amount)amount from dbo.billtable where trade_date >= '01 oct 2009' and trade_date <= '31 oct 2009' AND BRANCH='A' group by branch,Client_id) ORDER BY ter_branch tr DESC
there is one more table which contain branch names, if do while loop can take branch name as a variable
please help
Comment