select field1 from table1 where str1 like '%zo[0-9]%'
where field1 in ('z01','z02')
select * from table1 where field1 like '"+str1+"'
string tmpString[]=str1.Split("z"); string strTarget=string.empty; for(int i=0;i<tmpString.Length;i++) { strTarget+"'"+tmpString[i]+"',"; }string strCondition="("+strTarget.TrimEnd(",")+")";string strSql="select * from table where substring(field1,0,3) in "+strCondition;=================================================
where field1 like '%'+str1+'%'這樣可行否?
where field1 like '%'+str1+'%'
select * from table1 where field1 like 'Z01%' or field1 like 'Z04%' or field1 like 'Z03%'
eg : insert into testgroup values('z014564654') insert into testgroup values('z024564654') insert into testgroup values('z034564654') insert into testgroup values('z044564654')select * from testgroup where [name] like 'z0[0-9]%'result: 23 z014564654 24 z024564654 25 z034564654 26 z044564654 27 z014564654 28 z024564654 29 z034564654 30 z044564654
动态生成sql语句后再运行 declare @sqlstr varchar(1000) set @sqlstr='select * from table ' declare @s varchar(100) set @s='Z01,Z04,Z03' if len(@s)>0 begin set @sqlstr=@sqlstr+' where field1 like '+substring(@s,0,charindex(',',@s)) set @s=substring(@s,charindex(',',@s)+1,len(@s)) end WHILE len(@s) > 0 BEGIN set @sqlstr=@sqlstr+'or field1 like '+substring(@s,0,charindex(',',@s)) set @s=substring(@s,charindex(',',@s)+1,len(@s)) CONTINUE ENDexce(@sqlstr)
To: scorpiowell(年年岁岁花相似,岁岁年年人不同) 将 varchar 值 'select * from plan_day where roles_value like Z00' 转换为数据类型为 int 的列时发生语法错误。
select * from table1 where field1 in ('''' + replace('z01,z04,z03',',',''',''') + '''')
select * from table1 where field1 like '%'+str1+'%'
string strTarget=string.empty;
for(int i=0;i<tmpString.Length;i++)
{
strTarget+"'"+tmpString[i]+"',";
}string strCondition="("+strTarget.TrimEnd(",")+")";string strSql="select * from table where substring(field1,0,3) in "+strCondition;=================================================
where field1 like 'Z01%'
or field1 like 'Z04%'
or field1 like 'Z03%'
:
insert into testgroup values('z014564654')
insert into testgroup values('z024564654')
insert into testgroup values('z034564654')
insert into testgroup values('z044564654')select * from testgroup where [name] like 'z0[0-9]%'result:
23 z014564654
24 z024564654
25 z034564654
26 z044564654
27 z014564654
28 z024564654
29 z034564654
30 z044564654
declare @sqlstr varchar(1000)
set @sqlstr='select * from table '
declare @s varchar(100)
set @s='Z01,Z04,Z03'
if len(@s)>0
begin
set @sqlstr=@sqlstr+' where field1 like '+substring(@s,0,charindex(',',@s))
set @s=substring(@s,charindex(',',@s)+1,len(@s))
end
WHILE len(@s) > 0
BEGIN
set @sqlstr=@sqlstr+'or field1 like '+substring(@s,0,charindex(',',@s))
set @s=substring(@s,charindex(',',@s)+1,len(@s))
CONTINUE
ENDexce(@sqlstr)