日期:2014-05-16 浏览次数:20621 次
--创建组合查询存储过程
alter proc p_selectgroup
@cartype nvarchar(50),
@factory nvarchar(50),
@years int,
@status nvarchar(4)
as
declare @where varchar(200),@str varchar(200),@quotes varchar(200)
select @where =' where 1=1 ',@quotes = ''''
if @cartype<>''
set @where =@where +' and cartype =' + @quotes + @cartype + @quotes
if @factory<>''
set @where = @where +' and factory = ' + @quotes + @factory + @quotes
if @years<>''
set @where = @where +' and years =' + ltrim(@years)
if @status<>''
set @where = @where +' and status = ' + @quotes + @status + @quotes
set @str = 'select * from cars' + @where
print @str;
exec (@str)
go
create proc p_selectGroup
@CarType nvarchar(50),
@Factory nvarchar(50),
@Years int,
@Status nvarchar(4)
as
declare @where varchar(200),@str varchar(200)
set @where =' where 1=1 '
if @CarType<>''
set @where =@where +' and CarType = @CarType '
if @Factory<>''
set @where = @where +' and Factory = @Factory '
if @Years<>''
set @where = @where +' and Years = @Years '
if @Status<>''
set @where = @where +' and Status = @Status '
set @str =&nb