first sql store prucedure会者不难,难者不会!!!

老板说什么是什么!说做马上就得做,正费尽心思找着办法的时候告诉你不用作了。无法忍受也得忍受。第一次写存储过程,以前的sql脚本都是 用vba 或是asp等嵌入式语言写的。习惯了。这个没有做过。得用最短的时间学。没什么意义,记录以下自己的第一次的脚本。他是最关键的东写了。其他的比较好写。
终于找到循环的语句,得要做个游标哈哈。会者不难,难者不会!!!就这么点东西。
declare mycursor CURSOR for
select job_id from jobs
open mycursor
declare @i int
--set @i=0
fetch next from mycursor into @i
while (@@fetch_status<>-1)
begin
--set @i=@i+1
print @i
fetch next from mycursor into @i

end
close mycursor
deallocate mycursor
把自己考虑的程序伪语也写出来吧
if db exsit 
  drop table 
  create table sc39(pn var(10)) 
  select view --->maxclnm 
  for i=1 to maxclnm 
  clnm=price&i 
  alter table sc39 add clnm int 
  next 
  
  
  select * from view  
  pn,max 
  do while not eof 
  
  for i=1 to maxclnm 
  select * from sc390100 where sc39001=pn and sc39002=i 
  
  if eof  
  price=0 
  else 
  price=sc39004 
  end if 
  
  if i=1 
  insert into sc39 (pn,price) 
  else 
  update sc39 set price&i=price where pn=pn 
  end if 
  
  next 
  
  movenext 
  loop

原文地址:https://www.cnblogs.com/Mint/p/293540.html