表:a
字段:id,cname
declare @id int
while(类似select @id = id from a where cname = 'xxx ')
begin
select * from a where id =@ id
end
----
while里的语句要求判断是否有满足条件的id存在,不存在就不进入while循环,[email protected],并进入循环.
while结构不可改变(do...while)不在考虑之列.
------解决方案--------------------
while exists (select * from a where cname= 'xxx ')