日期:2014-05-18  浏览次数:20705 次

两张表没有联系 用模糊存储过成查出来 在线的用户帮帮忙 谢谢各位了
1 帖子表 2 资源表

SQL code

Create PROCEDURE PRO_SERCH
@postTitle varchar(100),
@resoutceTitle varchar(100)
as
Declare @Str_SQL nvarchar(MAX),
        @Choese varchar(10);
BEGIN
    if (@Choese='帖子')
    set @Str_SQL='select * from tb_Post where postTitle like ''%@postTitle %'' '
    if (@Choese='资源')
    set @Str_SQL='select * from tb_Resource where resoutceTitle like ''%@resoutceTitle %'' '
    exec(@Str_SQL)    
END



怎么改啊

------解决方案--------------------
SQL code
Create PROCEDURE PRO_SERCH
@postTitle varchar(100),
@resoutceTitle varchar(100)
as
Declare @Str_SQL nvarchar(MAX)

BEGIN
    if @postTitle is not null
    set @Str_SQL='select * from tb_Post where postTitle like ''%'+@postTitle +'%'''
    if @resoutceTitle is not null
    set @Str_SQL='select * from tb_Resource where resoutceTitle like ''%'+@resoutceTitle +'%'''
    exec(@Str_SQL)    
END