在过程中用like '%' 取数据可以,但是当用变量来代替'%'时取不出数据
ALTER procedure dbo.przcbnew (@nian1 char(4),@yue1 char(2),@ri1 char(2),@nian2 char(4),@yue2 char(2),@ri2 char(2),@dbm char(4),
@chex char(4),@cheh char(7),@pinm varchar(20),@pinl char(4),@zydd char(6),@daoz char(9),@daoj char(4) )
as
select @nian1=ltrim(rtrim(@nian1))
select @yue1=ltrim(rtrim(@yue1))
select @ri1=ltrim(rtrim(@ri1))
select @nian2=ltrim(rtrim(@nian2))
select @yue2=ltrim(rtrim(@yue2))
select @ri2=ltrim(rtrim(@ri2))
select @chex=ltrim(rtrim(@chex))
select @cheh=ltrim(rtrim(@cheh))
select @pinm=ltrim(rtrim(@pinm))
select @daoz=ltrim(rtrim(@daoz))
if len(@nian1)=0 select @nian1= '1999 '
if len(@nian2)=0 select @nian2= LTRIM(RTRIM(STR(year(GETDATE()))))
if len(@yue1)=0 select @yue1= '01 '
if len(@yue2)=0 select @yue2= LTRIM(RTRIM(STR(month(GETDATE()))))
if len(@ri1)=0 select @ri1= '01 '
if len(@ri2)=0 select @ri2= LTRIM(RTRIM(STR(DAY(GETDATE()))))
if @dbm= '不填 ' select @dbm= '% '
if len(@chex)=0 select @chex= '% '
if len(@cheh)=0 select @cheh= '% '
if len(@pinm)=0 select @pinm= '% '
if @pinl= '不填 ' select @pinl= '% '
if @zydd= '不填 ' select @zydd= '% '
if @daoj= '不填 ' select @daoj= '% '
if len(@daoz)=0 select @daoz= '% '
if len(@yue1)=1 select @yue1= '0 '+@yue1
if len(@ri1)=1 select @ri1= '0 '+@ri1
if len(@yue2)=1 select @yue2= '0 '+@yue2
if len(@ri2)=1 select @ri2= '0 '+@ri2
select @nian1,@yue1,@ri1,@nian2,@yue2,@ri2,@dbm,@chex,@cheh as 车号,@pinm,@pinl,@zydd,@daoz,@daoj
select
substring(a.riqixuhao,1,8),
case bb when 'A ' then '甲班 '
when 'B ' then '乙班 '
when 'C ' then '丙班 '
else '丁班 ' end,
cheh, chex, replace(fhr,char(10), ' '), pinm, pinl, daoz, daoj,
shiz, zydd, kssj, wlsj, hyy, zyb,dbm
from zcb a
where
cast(substring(riqixuhao,1,8) as datetime)> =cast(@nian1+@yue1+@ri1 as datetime) and
cast(substring(riqixuhao,1,8) as datetime) <=cast(@nian2+@yue2+@ri2 as datetime) and
(dbm like @dbm or