我在查询分析器里写了个脚本。内容是利用表A里的au和ed查出表B里的内容。由于表A里有多条记录,所以通过变量@i循环实现。
正常来说,肯定应该有结果的。但是现在检索结果为0条declare @i int
set @i=1
while @i<=2
begin
select * from istpallnew where au in (select au from temp where id=@i) and ed in (select ed from temp where id=@i)
set @i = @i + 1
end我的问题是:
1、语句错在哪里
2、如何打印中间变量谢谢,挺着急的!
正常来说,肯定应该有结果的。但是现在检索结果为0条declare @i int
set @i=1
while @i<=2
begin
select * from istpallnew where au in (select au from temp where id=@i) and ed in (select ed from temp where id=@i)
set @i = @i + 1
end我的问题是:
1、语句错在哪里
2、如何打印中间变量谢谢,挺着急的!
你的查询能不能写成:select a.*
from istpallnew a
inner join temp b on a.au = b.au and a.ed = b.ed
where b.id = @i
set @某字段 = ''
declare @i int
set @i=1
while @i <=2
begin
select @某字段 = 某字段 from istpallnew where au in (select au from temp where id=@i) and ed in (select ed from temp where id=@i)
set @i = @i + 1
print(@某字段)
end
from istpallnew a
inner join temp b on a.au = b.au and a.ed = b.ed
set @i=1
while @i<=1
begin
select a.* from istpallnew a inner join temp b on a.au like b.au + '%' and a.ed like b.ed + '%' where b.id = @i
set @i = @i + 1
end
我原来temp里的值是通过拷贝粘贴过去的,现在我用select into就得到结果了,谢谢!
马上给分!