存储过程经典用法
时间:2011-12-27 23:31来源: 作者:admin 点击: 次
SET QUOTED_IDENTIFIER ON
2 GO
3 SET ANSI_NULLS OFF
4 GO
5 if exists ( select * from dbo.sysobjects where id = object_id(N'[dbo].[GetOperationLogs]') and OBJECTPROPERTY(id, N 'IsProcedure') = 1)
6 drop procedure [dbo].[GetOperationLogs]
7 GO
8
9
10
11create procedure GetOperationLogs
12(
13 @useridList varchar(500),
14 @BeginTime datetime,
15 @EndTime datetime,
16 @description varchar(500)
17)
18as
19begin
20 declare @s varchar(2000)
21 set @s='select * from d_lg_6 '
22
23 if (( @useridList=null)and(@BeginTime=null)and(@EndTime=null)and(@Description=null))
24 begin
25 exec(@s)
26 return
27 end
28 set @s=@s+' where '
29
30 if ( @useridList!=null)
31 set @s=@s+' userid in ( '+@useridList+') and '
32
33 if (( @BeginTime!=null)and(@EndTime!=null))
34 set @s=@s+' logtime between '''+convert(varchar(19),@BeginTime,120)+''' and '''+convert(varchar(19),@endtime,120)+''' and '
35
36 if ( @Description!=null)
37 set @s=@s+' Description like ''%'+@Description+'%'''
38 if ( substring(@s,len(@s)-2,3)='and')
39 set @s=substring(@s,0,len(@s)-3)
40 exec(@s)
41 --select @s
42 --select substring(@s,len(@s)-2,3)
43end
44GO
45SETQUOTED_IDENTIFIER OFF
46GO
47SETANSI_NULLS ON
48GO(责任编辑:admin)
10
11create
13
15
16
17)
18as
19begin
20
21
22
23
24
25
26
27
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43end
44GO
45SET
47SET
