如果查询这几段字符串不在某字段中?

yyyrrr51 2009-05-25 10:28:01
"A0001","A0002","B0020","C0020"
以上是程序产生的一些字符串,怎么用一句语句判断哪个字符串不在数据库某字段中?

因为我想判断上面哪些是入库的,哪些是没入库的,没入库的取出来。

select * from tb where fd not in ("A0001","A0002","B0020","C0020")显然是不行,这句只是显示fd里不包含上面字符串的数据,列出这句主要是想提示不要误会我的意思。

注意,要反过来
...全文
88 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
linguojin11 2009-06-02
  • 打赏
  • 举报
回复
思路应该是首先将字符串整合到一A表中,然后判断A字段值是否存在与B表中的字段中。。。
石头大哥的UNION句也是这种原理
sharelove 2009-06-02
  • 打赏
  • 举报
回复
上邊的方法雖不行,但可以提供給你思路!
yyyrrr51 2009-06-01
  • 打赏
  • 举报
回复
忘了说我是在Access里,上面语句似乎都不行
水族杰纶 2009-05-26
  • 打赏
  • 举报
回复
--try
declare @str varchar(8000)
set @str=',A0001,A0002,B0020,C0020,'
select * from tb where charindex(','+fd+',',@str)=0
lihan6415151528 2009-05-26
  • 打赏
  • 举报
回复

select * from (select 'A0001' as fd union
select 'A0002' union select'B0020' union select'C0020')t
where fd not in(select fd from tb)
-狙击手- 2009-05-25
  • 打赏
  • 举报
回复
declare @s varchar(1000)
set @s = '"A0001","A0002","B0020","C0020"'
set @s = replace(@s,'","' ,''' as col union all select ''')
set @s = 'select '+replace(@s,'"' ,'''')
set @s = 'select col from ('+@s+'
) a where not exists(select 1 from tb where fd = a.col)'


exec( @s)
jinjazz 2009-05-25
  • 打赏
  • 举报
回复
select * from (select 'A0001' as fd union 
select 'A0002' union select'B0020' union select'C0020')t
where fd not in(select fd from tb)

22,209

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧