ggjj,帮帮忙!!这个sql条件如何写啊?

nicle_yang 2003-08-22 07:19:07
在我access表中有这样一列,类型为文本型,用来保存一个由0和1组成的串,如
"10010001",现在用相同类型的串去匹配,只要两个串同一位上都是1,就匹配成功,
而且这样的情况出现一趟就成功.
如:"10010" 和"10000",他们的第一位都是1,匹配成功.
大家帮帮忙吧,感激不禁!!!!!!!
...全文
37 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
zjcxc 元老 2003-08-23
  • 打赏
  • 举报
回复
declare @a varchar(100),@b varchar(100)
select @a='10',@b='100010'

if (cast(@a as bigint) & cast(@b as bigint))>0
print 'ok'
else
print 'no'
nboys 2003-08-23
  • 打赏
  • 举报
回复
或直接:

declare @a varbinary
set @a=10000000 --选择要匹配的数据
if exists(SELECT *
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\Finance\account.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...xactions where convert(int,@a&保存0和1的列)>0)
print '匹配成功'
else
print '没有找到匹配的数据'
nboys 2003-08-23
  • 打赏
  • 举报
回复
如果在access
先读到sqlserver

SELECT * into 新建表的名称
FROM OpenDataSource( 'Microsoft.Jet.OLEDB.4.0',
'Data Source="c:\Finance\account.xls";User ID=Admin;Password=;Extended properties=Excel 5.0')...xactions --Excel表单名称

然后:
declare @a varbinary
set @a=10000000 --选择要匹配的数据
if exists(select * from 新建表的名称 where convert(int,@a&保存0和1的列)>0)
print '匹配成功'
else
print '没有找到匹配的数据'
hjb111 2003-08-22
  • 打赏
  • 举报
回复
declare @a varchar
select @a=colname from yourtable
if cast(@a as varbinary) and 100000 <>0
print '匹配成功'
else
print '没有找到匹配的数据'
nboys 2003-08-22
  • 打赏
  • 举报
回复


try:

declare @a varbinary
set @a=11111111
if convert(decimal(10,0),@a&10010001)>0
print '匹配成功'
else
print '没有找到匹配的数据'
nboys 2003-08-22
  • 打赏
  • 举报
回复

declare @a varbinary
set @a=11111111

if exists(select * from tableName where convert(int,@a&columnName)>0)
print '匹配成功'
else
print '没有找到匹配的数据'
zsforever 2003-08-22
  • 打赏
  • 举报
回复
declare @string varchar(4000)
set @string = '?'
declare @i int ,@flag int
select @i=1,@flag=0
while @flag=0
begin
if @i>(select len(yourcolumn) from opendatesource('sqloledb','yourfile,uid id=admin;pwd=',)...yourtable where 条件)
begin
set @flag=-1
print 'no'
end
else if (select substring(yourcolumn,@i,1) from opendatesource('sqloledb','yourfile,uid id=admin;pwd=',)...yourtable where 条件)=substring(@string,@i,1)
begin
set @flag=1
print 'yes'
end
end
上面的打开方式有点忘了,自己查一下!
zsforever 2003-08-22
  • 打赏
  • 举报
回复
declare @string varchar(4000)
set @string = '?'
declare @i int ,@flag int
select @i=1,@flag=0
while @flag=0
begin
if @i>(select len(yourcolumn) from opendatesource('sqloledb','yourfile,uid id=admin;pwd=',)...yourtable where 条件)
begin
set @flag=-1
print 'no'
end
if (select substring(yourcolumn,@i,1) from opendatesource('sqloledb','yourfile,uid id=admin;pwd=',)...yourtable where 条件)=substring(@string,@i,1)
begin
set @flag=1
print 'yes'
end
end
上面的打开方式有点忘了,自己查一下!

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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