求语句合并经典写法,有答案,马上结帐送分
declare @message varchar(50)
set @message = '0755 '
--左模糊匹配
select * from AutoReply_DestCodeFilter where left(DestCode,Len(@message)) = @message and FetchMethod = 1
--右模糊匹配
select * from AutoReply_DestCodeFilter where Right(DestCode,Len(@message)) = @message and FetchMethod = 2
--任意匹配
select * from AutoReply_DestCodeFilter where DestCode like '%0755% ' and FetchMethod = 3
能否把 左模糊匹配,右模糊匹配,任意匹配三句合并成一条语句,谢谢!
------解决方案--------------------declare @message varchar(50)
set @message = '0755 '
--左模糊匹配
select * from AutoReply_DestCodeFilter where left(DestCode,Len(@message)) = @message and FetchMethod = 1 union all
--右模糊匹配
select * from AutoReply_DestCodeFilter where Right(DestCode,Len(@message)) = @message and FetchMethod = 2 union all
--任意匹配
select * from AutoReply_DestCodeFilter where DestCode like '%0755% ' and FetchMethod = 3
------解决方案--------------------select * from AutoReply_DestCodeFilter where charindex(@message,DestCode )> 0
------解决方案--------------------select * from AutoReply_DestCodeFilter where left(DestCode,Len(@message)) = @message and FetchMethod = 1 or Right(DestCode,Len(@message)) = @message and FetchMethod = 2 or DestCode like '%0755% ' and FetchMethod = 3
------解决方案----------------------try
select * from AutoReply_DestCodeFilter
where DestCode like
case FetchMethod
when 1 then '0755% '
when 2 then '%0755 '
when 3 then '%0755% '
else '%%% '
end
------解决方案--------------------marco08(天道酬勤) ( ) 信誉:100 Blog 2007-1-17 20:52:38 得分: 0
--try
select * from AutoReply_DestCodeFilter
where DestCode like
case FetchMethod
when 1 then '0755% '
when 2 then '%0755 '
when 3 then '%0755% '
else '%%% '
end
---------
赞