日期:2014-05-17 浏览次数:20596 次
string strsql = "select * from student where 1=1";
if(stuname!="")
{
strsql += "and stuname link '%name%'";
}
use testdb
go
if exists (select name from sysobjects where name='getStuList' and type='p')
drop procedure getStuList
go
create procedure getStuList
@stuid int,
@stuName nvarchar(50),
@stuBirthday datetime
AS
declare @sql nvarchar(1000)
set @sql='select s.stuID,s.stuName,s.stuSex,s.stuBirthday,s.stuAddress,s.stu_class_id
from Student as s where 1=1'
if @stuid!=null
begin
set @sql = @sql+'and s.stuid='+@stuid
end
EXEC(@sql)
go
use testdb
go
if exists (select name from sysobjects where name='getStuList' and type='p')
drop procedure getStuList
go
create procedure getStuList
@stuid int,
@stuName nvarchar(50),
@stuBirthday datetime
AS
declare @sql nvarchar(1000)
set @sql=' select s.stuID,s.stuName,s.stuSex,s.stuBirthday,s.stuAddress,s.stu_class_id
from Student as s where 1=1 '
if(@stuid is not null)
begin
set @sql = @sql+' and s.stuID='+convert(nvarchar,@stuid) + ' '
end
if(@stuName is not null)
begin
set @sql = @sql+' and s.stuName like ''%'+@stuName +'%'''
end
print (@sql)
go