- 积分
- 40165
- 好友
- 记录
- 主题
- 帖子
- 听众
- 收听
|
楼主 |
发表于 2013-1-24 15:08:15
|
显示全部楼层
给大家一现成的例子
[code=sql]set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[sp_select_icontype]
@id INT,
@typename NVARCHAR(20),
@filename NVARCHAR(20),
@CurrentPage int =1,
@PageSize int =10
AS
BEGIN
declare @strFields nvarchar(500);
declare @strWhere nvarchar(4000);
--查找的字段
SET @strFields='id,typename,filename,width,height';
--条件
SET @strWhere='1=1'
IF (@id<>-1) --id
BEGIN
SET @strWhere=@strWhere+'and id='+CONVERT(VARCHAR,@id)
END
IF (@typename<>'-1') --类型名称
BEGIN
SET @strWhere=@strWhere+'and typename like''%'+@typename+'%'''
END
IF (@filename<>'-1') --文件夹名称
BEGIN
SET @strWhere=@strWhere+'and filename like''%'+@filename+'%'''
END
EXEC ('select '+@strFields+' from table '+@strWhere)
END
[/code] |
|