Advertisement
Guest User

sqlmishany

a guest
Apr 17th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.62 KB | None | 0 0
  1. Declare @i int, @data1 date,@data2 date,@cost1 real, @cost2 real,@result real,@a real
  2. Declare @tableNaso Table (table_data date,result real)
  3. Declare @tableUSD Table (table_data1 date,result1 real)
  4. Declare @result_table Table (table_data1 date,res varchar(50))
  5. Declare Naso_Cursor Cursor global forward_only dynamic read_only
  6. For Select Date, ClosingPrice from MailRuCostNaso
  7. Open Naso_Cursor
  8. set @i=0
  9. Fetch next from Naso_Cursor into @data1,@cost1
  10. while @@FETCH_STATUS=0
  11. begin
  12. set @i = @i+1
  13. FETCH NEXT FROM Naso_Cursor into @data2,@cost2
  14. if (@cost2 =0 )
  15. begin
  16. set @cost2= (Select ClosingPrice from MailRuCostBer where Date=@data2)
  17. end
  18. set @result=@cost2-@cost1
  19. Insert into @tableNaso (table_data,result) values (@data1,@result)
  20. set @data1=@data2
  21. set @cost1=@cost2
  22. end
  23. close Naso_Cursor
  24. deallocate Naso_Cursor
  25. Declare USD_Cursor Cursor global forward_only dynamic read_only
  26. For Select Date, ClosingPrice from USDCos
  27. Open USD_Cursor
  28. set @i=0
  29. Fetch next from USD_Cursor into @data1,@cost1
  30. while @@FETCH_STATUS=0
  31. begin
  32. set @i = @i+1
  33. FETCH NEXT FROM USD_Cursor into @data2,@cost2
  34. set @result=@cost2-@cost1
  35. Insert into @tableUSD (table_data1,result1) values (@data1,@result)
  36. set @data1=@data2
  37. set @cost1=@cost2
  38. end
  39. close USD_Cursor
  40. deallocate USD_Cursor
  41. Declare Result_Cursor Cursor global forward_only dynamic read_only
  42. For Select table_data,result from @tableNaso
  43. Open Result_Cursor
  44. set @i=0
  45. Fetch next from Result_Cursor into @data1,@cost1
  46. while @@FETCH_STATUS=0
  47. begin
  48. set @i = @i+1
  49. set @a=( Select result1 from @tableUSD where table_data1=@data1)
  50. if (@a>0 and @cost1>0)
  51. Insert into @result_table(table_data1,res) values (@data1,'both grows')
  52. if (@a>0 and @cost1<0)
  53.  Insert into @result_table(table_data1,res) values (@data1,'Rub grows MailRu falls')
  54.  if (@a<0 and @cost1>0)
  55.  Insert into @result_table(table_data1,res) values (@data1,'MailRu grows Rub falls')
  56.  if (@a<0 and @cost1<0)
  57.  Insert into @result_table(table_data1,res) values (@data1,'both falls')
  58.  if (@a<0 and @cost1=0)
  59.  Insert into @result_table(table_data1,res) values (@data1,'MailRu holds Rub falls')
  60.  if (@a=0 and @cost1<0)
  61.  Insert into @result_table(table_data1,res) values (@data1,'Rub holds MailRu falls')
  62.  if (@a=0 and @cost1=0)
  63.  Insert into @result_table(table_data1,res) values (@data1,'both holds')
  64.  if (@a>0 and @cost1=0)
  65.  Insert into @result_table(table_data1,res) values (@data1,'MailRu holds Rub grows')
  66.  if (@a=0 and @cost1>0)
  67.  Insert into @result_table(table_data1,res) values (@data1,'MailRu grows Rub holds')
  68. FETCH NEXT FROM Result_Cursor into @data1,@cost1
  69. end
  70. close Result_Cursor
  71. deallocate Result_Cursor
  72. select * from @result_table
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement