存储过程参数书写格式问题!急!急!!急!!!
创建的代码如下:请问各位大虾,在like中的参数应该怎样写:(其他的都已经可以的了,就是参数那里不知书写格式)
alter proc DanPinXiaoShouMaoLiPaiHangBang
@DateFrom varchar(50),
@DateTo varchar(50),
@String varchar(50)
as
select PhyID,
PhyName,
Spec,
Unit,
Producer,
sum(XiaoShouE) as TotalXiaoShouE
from dbo.DanPinXiaoShouTongJi
where PhyID like '@String% '
and convert(smalldatetime,BillDate,120) between @DateFrom and @DateTo
or
PhyName like '@String% '
and convert(smalldatetime,BillDate,120) between @DateFrom and @DateTo
group by PhyID,
PhyName,
Spec,
Unit,
Producer
order by TotalXiaoShouE desc
------解决方案--------------------wherePhyID like '@String% '
PhyName like '@String% '
--> 改为
wherePhyID like @String + '% '
PhyName like @String + '% '
如果是全模糊,需要两边加%,如:
wherePhyID like '% ' + @String + '% '
PhyName like '% ' + @String + '% '