翻阅古今
由于不知道你是用SQLSERVER还是ORACLE,我就先给你一个SQLSERVER版本的吧!如果你的字段定义是id为字符类型(nvarchar或varchar),而goid也是字符类型的话就很简单了!直接用like或者charindex就行了!测试sql如下:create table #1(id varchar(10),goid varchar(10));insert into #1( id,goid)values('123456','345'),('222444','123'),('56789','89'),('123','1');select * from #1 where id like '%'+goid+'%';select * from #1 where charindex(goid,id)>0;drop table #1;如果你的字段定义是id为字符类型(nvarchar或varchar),而goid是整型(int,tinyint等)的话就要转换一下!测试sql如下:create table #2(id varchar(10),goid int);insert into #2( id,goid)values('123456',345),('222444',123),('56789',89),('123',1);select * from #2 where id like '%'+convert(varchar,goid)+'%';select * from #2 where charindex(convert(varchar,goid),id)>0;drop table #2;如果不属于上面两种情况,参考照转换方法都可以解决!下面是ORACLE版本的!因为ORACLE会自己来处理这些问题,直接用like或instr就行了!不分类型哈!测试sql如下:create table t1 (id nvarchar2(10),goid varchar(10));insert into t1( id,goid)values('123456','345');insert into t1( id,goid)values('222444','123');insert into t1( id,goid)values('56789','89');insert into t1( id,goid)values('123','1');select * from t1 where id like '%'||goid||'%';select * from t1 where instr(id,goid)>0;drop table t1;