select * from part where id in (select left(right(partid,len(partid)-1),len(right(partid,len(partid)-1))-1) from kind where id=1)-----------------请问此语句有什么问题吗?使用此语句没有结果!但语句“select left(right(partid,len(partid)-1),len(right(partid,len(partid)-1))-1) from kind where id=1”的反回值为:" ,1,3,5,7,8,"将问题语句修改为:select * from part where id in (1,3,5,7,8)----------------此语句又能正常得到结果!请高手指点,问题在哪儿?应如何才能得到正确结果呢?
select * from part where id in ('1,3,5,7,8')
select * from part where id in (1,3,5,7,8)
from part
where id in
(select left(
right(partid,len(partid)-1),
len(right(partid,len(partid)-1))-1
)
from kind
)
declare @s as nvarchar(200)select @s=left(right(partid,len(partid)-1),len(right(partid,len(partid)-1))-1
from kind where id=1select @s='select * from part where id in (' + @s + ')' print @sexec @s
from part
where id in
(select left(
right(partid,len(partid)-1),
len(right(partid,len(partid)-1))-1
)
from kind
where id=1
)
里面漏了id=1
from kind where id=1))>0
select
*
from
part
where
charindex(','+cast(id as varchar(10))+',',(select
left(right(partid,len(partid)-1),
len(right(partid,len(partid)-1))-1)
from
kind
where
id=1))>0
Access在Access中declare不知道杂用了~~
回个贴真难,还得换个号才行!库比较简单:
表Part:
id(int) partname(varchar) description(memo) situation(int)
1 adfsdf rwerfsdf 1
2 sfiwf wrw23fsdfdf 1
3 sdmkls fsdfsd 1
......表Kind:
id(int) kindname(varchar) description(memo) situation(int) partid(varchar)
1 fsdfsd dsklwet 1 ,1,3,5,7,8,
2 sdfsd kfg34trrre 1 ,3,4,6,8,
3 rgdf kdfdfg 1 ,1,2,5,
......