一、7|3|1,8|6|1,3|1|1,16|1|1,5|7|1,9|7|1
二、6|3|1,7|3|1,8|6|1,2|1|1,3|1|1,16|1|1,4|7|1,5|7|1,9|7|1,10|7|1,11|4|1,12|4|1,13|4|1,14|5|1,15|5|1,17|0|1
怎样查询 一 在 二 里面并输出记录集。
SQL code:
declare @one varchar(1000),@two varchar(1000)
set @One='7|3|1,8|6|1,3|1|1,16|1|1,5|7|1,9|7|1'
set @two='6|3|1,7|3|1,8|6|1,2|1|1,3|1|1,16|1|1,4|7|1,5|7|1,9|7|1,10|7|1,11|4|1,12|4|1,13|4|1,14|5|1,15|5|1,17|0|1'
select case when charindex(@one,@two)>0 then '存在' else 'NO' end
使用charindex来判断,即:charindex(要判断的字符,字符),返回>0代表存在,否则不存在
SQL code:
select * form table where a like '%7|3|1,8|6|1,3|1|1,16|1|1,5|7|1,9|7|1 %'
建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进