现在的位置: 首页 > 综合 > 正文

常用sqlserver存储过程

2012年05月16日 ⁄ 综合 ⁄ 共 707字 ⁄ 字号 评论关闭
 1 ------------------------------------
 2 --用途:查询列表,返回前几条或者全部
 3 --项目名称:
 4 --说明:
 5 --时间:2012/8/15 12:16:41
 6 ------------------------------------
 7 ALTER PROCEDURE [dbo].[GetTopList_Pro]
 8 @tbname varchar(30),
 9 @cols varchar(400),
10 @top int=0,
11 @strWhere varchar(1000)='',
12 @orderby varchar(1000)=''
13 AS
14     declare @strTop varchar(30)=''
15     if @strWhere!=''
16     set @strWhere=N' where '+ @strWhere
17 
18     if @orderby!=''
19     set @orderby=N' order by '+ @orderby
20 
21     if @cols=''   
22     set @cols=N' * '
23 
24     if @top>0
25     set @strTop=N' top '+ convert(varchar,@top)
26     
27     /* SET NOCOUNT ON */
28     exec(N'select  '
29     +N' '+@strTop
30     +N' '+@cols
31     +N' from '+@tbname
32     +N' '+@strWhere
33     +N' '+@orderby)
34     
35     
36     print N'select  '
37     +N' '+@strTop
38     +N' '+@cols
39     +N' from '+@tbname
40     +N' '+@strWhere
41     +N' '+@orderby
42     RETURN

 

 

抱歉!评论已关闭.