Paging Stored procedures:
CREATE PROCEDURE [dbo]. [GetData]
--Add The parameters for the stored procedure here
@tb varchar (150),
@status varchar (800),
@indexpage int,
@endpage int
As
DECLARE @str varchar (5000)
If @status is null
BEGIN
Set @str = ' SELECT * FROM (select Row_number () over (order by t.id Desc) as ROW, t.* from ' [email protected]+ ' T where ' [Emai L protected]+ ') TT WHERE TT. Row between ' +str (@indexpage) + ' and ' +str (@endpage)
EXEC (@str)
END
Else
BEGIN
Set @str = ' SELECT * FROM (select Row_number () over (order by t.id Desc) as ROW, t.* from ' [email protected]+ ' T where ' [Emai L protected]+ ') TT WHERE TT. Row between ' +str (@indexpage) + ' and ' +str (@endpage)
EXEC (@str)
END
CREATE PROCEDURE [dbo]. [Getexport]
@status varchar (5000),
@tb varchar (80),
@s NCHAR (2)
As
DECLARE @sql varchar (5000)
If @status is null
BEGIN
Set @sql = ' select * from ' [email protected]+ '
EXEC (@sql)
END
Else
BEGIN
If @tb = ' Outputcomponet_view '
If @s= ' warehousing '
Set @sql = ' Select T.componentname as accessory name, t.typename as type, t.unit1 as unit, t.count as quantity, t.price as Price, (T.count*t.price) as Total amount, t.supplier1 as supplier, t.isold as whether old piece, t.warehouse1 as Warehouse, t.adddate as ' [email protected]+ ' from ' [email protected]+ ' as T where ' [email protected]+ '
Else
Set @sql = ' Select T.componentname as accessory name, t.typename as type, t.unit1 as unit, t.count as quantity, t.price as Price, (T.count*t.price) as Total amount, t.company as borrowing company, T.isold as whether old pieces, t.warehouse1 as Warehouse, t.adddate as ' [email protected]+ ' from ' [email protected]+ ' as T where ' [email protected]+ '
else if @tb = ' Borrowdetail_view '
If @s= ' lending '
Set @sql = ' Select T.componentname as accessory name, t.typename as type, t.unit1 as unit, t.count as quantity, t.price as Price, t.borrower borrower, T.compa NY borrowing company, t.department borrowing department, t.isold whether old pieces, t.adddate as ' [email protected]+ ' from ' [email protected]+ ' as t where ' [email prot ected]+ "
Else
Set @sql = ' Select T.componentname as accessory name, t.typename as type, t.unit1 as unit, t.count as quantity, t.price as price, t.borrower return person, T.compa NY return company, T.department return department, t.isold whether old pieces, t.adddate as ' [email protected]+ ' from ' [email protected]+ ' as t where ' [email prot ected]+ "
else Set @sql = ' select * from ' [email protected]+ '
EXEC (@sql)
END
SQL Dynamic Stored Procedures