當你想對表里面的數據一條一條處理的時候﹐你可以考慮使用游標.
declare aa  cursor
for select code ,name ,sex from table order by  code
open aa
fetch next from aa into @code,@name,@sex
while @@fetch_status<>0
begin
  if @sex='m' and substring(@code,1,2)='wy' 
  insert into table1 (code,name,sex) values(@code,@name,@sex)
  fetch next from aa into @code,@name,@sex
end
close aa
deallocate aa
一般不使用游標﹐你比如上面這些用一句就可以。
insert into table1 select code,name,sex from table where sex='m' and substring(code,1,2)='wy'