Click here to Skip to main content
16,014,613 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
hello sir,

I wrote a stored procedure. I am retrieving some rows from 3 tables using joins. I have a text box in the page.

What value I entered in that textbox, that much of rows can be retrieved. My stored procedure is
SQL
alter proc [dbo].[SP_FastMovingItem_Value]
	  (
	  @Location varchar(20),
	  @FromDate datetime,
	  @ToDate datetime,
	  @Rows int
	  )
	  as
	   begin
			  
			  if Exists(Select Name From Sysobjects where Name='Temp_FastMovingItem_Value')
		Begin
			Drop Table Temp_FastMovingItem_Value
		End
	 SET ROWCOUNT @Rows
 
	Select Location.LocName,MBillTran.BillTranItemCode, MenuMaster.MenuItemLnName, Sum(MBillTran.BillTranQty*MBillTran.BillTranRate) AS TotValue,
	Department.DeptName, MainGroup.MainGrpDesc into  Temp_FastMovingItem_Value
	From MBillTran, MenuMaster, Department, MainGroup,Location  
	Where MBillTran.BillTranItemCode = MenuMaster.MenuItemCode And MBillTran.BillTranDeptCode = Department.DeptCode 
	And MenuMaster.MenuDeptCode = Department.DeptCode And MenuMaster.MenuItemGrpCode = MainGroup.MainGrpCode 
	And MBillTran.BillTranExcepFlag<>'V' And MBillTran.BillTranExcepFlag<>'O' And MBillTran.BillTranUpdated='Y' 
	And MBillTran.BillTranExcepFlag='B' And MBillTran.BillTranLocCode=Location.LocCode 
	And Convert(Char(10),BillDate,111)>=CONVERT(nvarchar(20), @FromDate ,111)  And Convert(Char(10),BillDate,111)<=CONVERT(nvarchar(20), @ToDate ,111)
	And MBillTran.BillTranLocCode =(CASE @Location WHEN '0' THEN MBillTran.BillTranLocCode ELSE @Location END)
	
	GROUP BY Location.LocName,MBillTran.BillTranItemCode, MenuMaster.MenuItemLnName, MBillTran.BillTranExcepFlag, 
	Department.DeptName,  MainGroup.MainGrpDesc ORDER BY Sum(MBillTran.BillTranQty*MBillTran.BillTranRate) DESC
	
	SET ROWCOUNT 0
	select max(@Rows) from Temp_FastMovingItem_Value
		end
Posted
Updated 26-Oct-10 23:15pm
v3
Comments
Hiren solanki 27-Oct-10 4:57am    
Edited code blocks.
Arindam Tewary 27-Oct-10 5:00am    
Whats your question?
Rajesh Anuhya 27-Oct-10 5:09am    
there is no Question ???, what is your question???

1 solution

Let me give you general idea for this scenario.

For that very reason pass value of TextBox ( which states how many rows you want to retrieve from DB ) as a parameter to stored procedure

i.e.
exec dbo.Test 23


Now at the receiving side catch this parameter and set ROWCOUNT Accordingly.

i.e.
SQL
CREATE PROCEDURE Test
@rowscount int
AS
begin
SET ROWCOUNT @rowscount;
select * from Person.Address
end


Which will return you desired number of rows.

Hope that helps.
Please vote and Accept Answer if it Helped.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900