码迷,mamicode.com
首页 > 数据库 > 详细

sql 动态存储过程

时间:2015-04-16 12:17:15      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:

 

分页存储过程:

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 ‘+@tb+‘ T where ‘+@status+‘ ) 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 ‘+@tb+‘ T where ‘+@status+‘ ) 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 ‘+@tb+‘‘
exec(@sql)
END
else
BEGIN
if @tb=‘OutPutComponet_View‘
if @s=‘入库‘
set @sql=‘select t.ComponentName as 配件名称, t.TypeName as 类型,t.Unit1 as 单位,t.Count as 数量,t.Price as 价格,(t.Count*t.Price) as 总金额,t.Supplier1 as 供应商,t.IsOld as 是否旧件,t.WareHouse1 as 仓库,t.AddDate as ‘+@s+‘ from ‘+@tb+‘ as t where ‘+@status+‘‘
else
set @sql=‘select t.ComponentName as 配件名称, t.TypeName as 类型,t.Unit1 as 单位,t.Count as 数量,t.Price as 价格,(t.Count*t.Price) as 总金额,t.Company as 借用公司,t.IsOld as 是否旧件,t.WareHouse1 as 仓库,t.AddDate as ‘+@s+‘ from ‘+@tb+‘ as t where ‘+@status+‘‘
else if @tb=‘BorrowDetail_View‘
if @s=‘借出‘
set @sql=‘select t.ComponentName as 配件名称,t.TypeName as 类型,t.Unit1 as 单位,t.Count as 数量,t.Price as 价格,t.Borrower 借用人,t.Company 借用公司,t.Department 借用部门,t.IsOld 是否旧件,t.AddDate as ‘+@s+‘ from ‘+@tb+‘ as t where ‘+@status+‘‘
else
set @sql=‘select t.ComponentName as 配件名称,t.TypeName as 类型,t.Unit1 as 单位,t.Count as 数量,t.Price as 价格,t.Borrower 归还人,t.Company 归还公司,t.Department 归还部门,t.IsOld 是否旧件,t.AddDate as ‘+@s+‘ from ‘+@tb+‘ as t where ‘+@status+‘‘
else set @sql=‘select * from ‘+@tb+‘‘
exec(@sql)

END

sql 动态存储过程

标签:

原文地址:http://www.cnblogs.com/anyben/p/4431584.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!