declare @s varchar(10) set @s='32915762' select * from tb where replace(replace(货号,'-',''),'0','')=@s
select * from tb where left(货号,charindex('-',货号)-1)+ltrim(cast(right(货号,len(货号)-charindex('-',货号)) as int))='32915762'
where 货号 like '32915%762%'
replace 0 显然是不行的,如果后面的数字是702就不行了
用replace 把0替换了,万一里面有的0不用替换,就不对了 所有要看具体要求
where 货号 like '32915%762' 或者将列中的0去掉,如楼上所说。
declare @t table(f1 varchar(15))insert @t select '32915-000000762' union all select '32915-000000763' union all select '32915-000000764' union all select '32915-000000765'declare @str varchar(15) set @Str='32915762' set @str=left(@Str,5)+'-'+right('000000000'+substring(@Str,6,15),9)print @Strselect * from @t where f1=@str
--楼主的SQL语句是什么?没有使用模糊查询吧!like '%32915762%'
set @s='32915762'
select *
from tb
where replace(replace(货号,'-',''),'0','')=@s
from tb
where
left(货号,charindex('-',货号)-1)+ltrim(cast(right(货号,len(货号)-charindex('-',货号)) as int))='32915762'
where 货号 like '32915%762%'
所有要看具体要求
where 货号 like '32915%762' 或者将列中的0去掉,如楼上所说。
select '32915-000000762' union all
select '32915-000000763' union all
select '32915-000000764' union all
select '32915-000000765'declare @str varchar(15)
set @Str='32915762'
set @str=left(@Str,5)+'-'+right('000000000'+substring(@Str,6,15),9)print @Strselect *
from @t
where f1=@str