当前位置: 代码迷 >> Sql Server >> 存储过程可以模糊查询吗?该如何解决
  详细解决方案

存储过程可以模糊查询吗?该如何解决

热度:82   发布时间:2016-04-27 13:09:03.0
存储过程可以模糊查询吗?????????????
SQL code
create procedure book_history @bname char(30)='SQL%'aswith cte_bookas (select * from book08 where bname like @bname)select cte_book.bname,history08.*,reader08.namefrom cte_book left outer join history08 join reader08on reader08.lno = history08.lnoon cte_book.ISBN = history08.ISBNgoexecute book_history


解释一下。存储过程没有错,就是查不出数据。当execute book_history改成execute book_history 'SQL server 2008实用教程'时,就有数据
是不是存储过程不支持模糊查询啊???

------解决方案--------------------
select * from book08 where bname like 'SQL%'


有没有结果先

过程当然支持模糊查询!
------解决方案--------------------
SQL code
--直接拼串就可以实现你的功能create procedure book_history    @bname char(30)    /*模糊查询的关键字*/as     declare @sql nvarchar(1024)        set @sql = '一段SQL语句'+‘%' + convert(nvarchar(50),@bname) + '%''        exec(@sql)    go
------解决方案--------------------
支持的,建议你把数据表发上来,数据发上来 大家帮你看看
------解决方案--------------------
char(30)=

改为 varchar(30) 看看
  相关解决方案