1. declare @x int,@y int,@z int 
  2. select @x=1,@y=2,@z=3--t-sql里面用select进行赋值,而存储过程或者游标中用set进行赋值  
  3. if @x>@y  
  4. print 'x>y' 
  5. else if @y>@z  
  6. print 'y>z' 
  7. else print 'z>y' 
  8.  
  9. declare @x int ,@y int ,@c int 
  10. select @x=1,@y =1  
  11. while @x<3  
  12. begin 
  13. print @x  
  14. while @y<3  
  15. begin 
  16. select @c = 100*@x+@y  
  17. print @c  
  18. select @y=@y+1  
  19. end 
  20. select @x=@x+1  
  21. select @y=1  
  22. end 
  23.  
  24. --以下是waitfor的用法看起来很好玩  
  25. waitfor delay '00:00:30'--过30秒后执行以下程序  
  26. select * from student  
  27. waitfor time '18:18:18'--到晚上18:18:18的时候执行以下的语句   
  28. select * from student