小弟遇到一个难题先说明如下: 表一 TypeID ClassID typeName
38 11 a
39 11 b
28 12 c 表二 id BlogTypeList
1 ~38~39
2 ~38~40~89~56
3 ~40~89~56
4 ~12~34~34如上的2张表 现在查找出ClassID=11的 TypeID 38,39然后查出BLoggTypeList 里面含有 38 39 的id 。
38 11 a
39 11 b
28 12 c 表二 id BlogTypeList
1 ~38~39
2 ~38~40~89~56
3 ~40~89~56
4 ~12~34~34如上的2张表 现在查找出ClassID=11的 TypeID 38,39然后查出BLoggTypeList 里面含有 38 39 的id 。
解决方案 »
- 在应用程序级别之外使用注册为 allowDefinition='MachineToApplication' 的节是错误的。如果在 IIS 中没有将虚拟目录配置为应用程序,则可能导致此错误。
- jquery如何获取客户端ip地址??
- 我的那个字符串很多 请大家帮忙
- 有哪位可以帮忙设计一个在线答题系统(请说具体点吧)
- 问一个word的问题急急
- 疑难杂症呀,请大家进来看看
- 一个简单的问题。望高手指点
- 高手!问一下 在地址栏里最后一个字母后输入/的时候 为什么报错 怎么解决??
- ====如何统一格式化DataGrid控件的外观====
- 关于Validator
- 菜鸟提问:数据绑定
- gridview在删除时无法获的主键的值
from 表二 b
left join 表一 a
on b.BlogTypeList like '%'+a.TypeID+'%'
where a.ClassID = 11
但楼主如果要的是BlogTypeList 同时包含38和39 就不好使
from t2 b
left join t1 a
on b.BlogTypeList like '%'+cast(a.TypeID as varchar)+'%'
where a.ClassID = 11
--> 测试数据: #T1
if object_id('tempdb.dbo.#T1') is not null drop table #T1
create table #T1 (TypeID int,ClassID int,typeName nvarchar(255))
insert into #T1
select 38,11,'a' union all
select 39,11,'b' union all
select 28,12,'c'
--> 测试数据: #T2
if object_id('tempdb.dbo.#T2') is not null drop table #T2
create table #T2 (id int,BlogTypeList nvarchar(255))
insert into #T2
select 1,'~38~39' union all
select 2,'~38e40~89e56' union all
select 3,'~40e89~56' union all
select 4,'~12e34~34'
select b.id
from #T2 b left join #T1 a on (b.BlogTypeList like '%'+cast(a.TypeID as varchar(10))+'%') where a.ClassID = 11 GROUP BY b.id--现在查找出ClassID=11的 TypeID 38,39然后查出BLoggTypeList 里面含有 38 39 的id
--id
-------------
--1
--2
from 表二 b
left join 表一 a
on b.BlogTypeList like '%'+a.TypeID+'%'
where a.ClassID = 11
id BlogTypeList
1 38
2 40
3 89
4 56
select id from T2 a where exists(select 1 from T1 b where ClassID = 11
and charindex(a.BlogTypeList+'~','~'+ltrim(b.TypeID)+'~')>0)
select id from T2 a where exists(select 1 from T1 b where ClassID = 11
and charindex('~'+ltrim(b.TypeID)+'~',a.BlogTypeList+'~')>0)
select id from @T2 a where exists(select 1 from @T1 b where ClassID = 11
and charindex('~'+ltrim(b.TypeID)+'~',a.BlogTypeList+'~')>0)
--Result
/*
id
-----------
1
2
*/