--方法一
Select * From A Where CharIndex(FormNO, @Str) > 0
--方法二
Select * From A Where @Str Like '%' + FormNO + '%'
--方法三
Select * From A Where PatIndex('%' + FormNO + '%', @Str) > 0
Select * From A Where CharIndex(FormNO, @Str) > 0
--方法二
Select * From A Where @Str Like '%' + FormNO + '%'
--方法三
Select * From A Where PatIndex('%' + FormNO + '%', @Str) > 0
现在有一字符串 Str 格式为:
XXXXXX,XXXXXX,XXXXXX,.........求SQL查找表A中所有的FormNO出现在Str中的记录。select * from a where charindex(','+formno+',',','+@str+',')>0
Select * From A Where CharIndex(FormNO, @Str) > 0
--方法二
Select * From A Where @Str Like '%' + FormNO + '%'
--方法三
Select * From A Where PatIndex('%' + FormNO + '%', @Str) > 0
#include <iostream>
#include <conio.h>
#include <fstream.h>
#include <assert.h>int main(int argc, char* argv[])
{
char buf[SZ];
int i = 1;
assert(argc == 3);
ifstream in(argv[1]);
assert(in);
char *str = argv[2];
assert(str);
while(in.getline(buf,SZ))
{
char* cp = buf;
char* ca = str;
while(*cp)
{
char *cl = cp;
while(*cl == *ca)
{
cl++;
ca++;
if(*ca == '\0'||cl == '\0')
break;
}
if(*ca == '\0')
cout<<i<<endl;
ca = str;
cp++;
}
i++;
}
system("pause");
// 这句会显示“请按任意键继续……”系统命令
// 要想停住,还可以getchar()
getch();
return 0;
}
// 运行方式(编译后保存为find.exe)为: find filename.txt str_need_find