当前位置: 代码迷 >> Sql Server >> 存储过程中like 项如何写
  详细解决方案

存储过程中like 项如何写

热度:38   发布时间:2016-04-27 16:49:02.0
存储过程中like 项怎么写?
CREATE   PROCEDURE   AView
    @a   nvarchar(100)   ,
    @b   nvarchar(100)  
AS  
SELECT  
c,d,e
FROM   table
WHERE   c   like   '[email protected]% '   OR   d   like   '[email protected]% '   ORDER   BY   e
GO

这个存储过程正确应该如何写?

------解决方案--------------------
CREATE PROCEDURE AView
@a nvarchar(100) ,
@b nvarchar(100)
AS
SELECT c,d,e
FROM table
WHERE c like '% '[email protected]+ '% ' OR d like '% '+@+ 'b% '
ORDER BY e
GO

------解决方案--------------------
CREATE PROCEDURE AView
@a nvarchar(100) ,
@b nvarchar(100)
AS
exec( 'SELECT
c,d,e
FROM table
WHERE c like ' '% '[email protected]+ '% ' ' OR d like ' '% '[email protected]+ '% ' ' ORDER BY e ')
GO

------解决方案--------------------
create table t(ID varchar(20),date datetime)
insert t select '001 ', '2006/02/02 '
union all select '001 ', '2006/02/05 '
union all select '002 ', '2006/05/02 '
union all select '002 ', '2006/05/05 '
go
select * from t
create procedure pr_1
@a varchar(20)
as
select * from t where ID like '% '[email protected]+ '% '

exec pr_1 1
  相关解决方案