NEERAJPRASADSHARMA

sql server in performance the problem

Apr 29th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
T-SQL 2.17 KB | None | 0 0
  1. site :https://sqlserverqueryperformance.wordpress.com/2016/04/28/sql-server-in-performance-the-problem/
  2. by NEERAJ PRASAD SHARMA
  3.  
  4.  
  5. Create table #counter (variablecount int primary key , milliseconds varchar(10))
  6.  
  7. declare @values nvarchar (max)
  8. select  @values=  ('3279615,  2619534,  2932146,  4953386,  2818224,  5244141,  2321234,  4670287,  3600354,  4307158,  4668756,  4049137,  3037542,  4483522,  3660501,  4426646,  3110987,  2709820,  2818736,  4875826,  2029820,  5467223,  2316672,  2080036,  3781872,  5120161,  4231500,  2885329,  2186636,  4273746,  4469182,  4682959,  3905551,  3206172,  2911743,  4275209,  3789552,  2341547,  2943986,  5229815,  2867115,  2402580,  2943328,  3125357,  4816147,  4219152,  3825625,  3221610,  5052178,  4742174,  2182772,  4934910,  5196299,  3803372,  5041037,  4261499,  5266382,  3667876,  3467411,  2574704,  3941358,  3785855,  4258958,  4565076,  5274231,  3203938,  5329843,  4438383,  2312628,  3248408,  3743514,  4552594,  4109833,  4388393,  5064054,  2054373,  3715411,  3761234,  5470921,  5197951,  4356672,  3309015,  3767928,  2372922,  3858804,  3617027,  3247204,  2105261,  2846260,  3053944,  4398447,  3246406,  4326008,  2506261,  5404760,  2410146,  3578365,  2753024,  3164078,  4087679')
  9. Declare @dynamicsql nvarchar(max)
  10. declare @loop int ,@LoopCount int
  11. set @loop = 7
  12. Set @LoopCount= 1
  13.  
  14. while (@loop <997)
  15. BEGIN
  16. SET @dynamicsql =
  17. 'declare @Beforeexecutiontime datetime
  18. declare @Aeforeexecutiontime datetime
  19. declare @ID int
  20. declare @IDvarchar varchar(50)
  21. declare @INTCLOUMN int
  22. declare @Name varchar(50)
  23. declare @Age int
  24. declare @Randomvalue bigint
  25. Set @Beforeexecutiontime=getdate()
  26. Select @ID=ID , @IDVARCHAR=IDvarchar ,@INTCLOUMN=intcolumn, @NAME=Name ,@AGE=Age ,@RANDOMVALUE=Randomvalue from TestTable
  27. where id in
  28. (' +Convert (Nvarchar(max), left ( @values,@loop))+ ')
  29. option (MAXDOP 1)
  30. SET @Aeforeexecutiontime =getdate()
  31. INSERT INTO #counter
  32. select '+ Convert (Nvarchar(10),@LoopCount)+',datediff (MS ,@Beforeexecutiontime ,@Aeforeexecutiontime)
  33. '
  34.  
  35.  
  36. EXEC( @dynamicsql)
  37. set @loop= @loop+10
  38. SET @LoopCount =@LoopCount+1
  39. SET @dynamicsql =''
  40. END
  41.  
  42.  
  43.  
  44.  
  45.  
  46. select * from #counter
  47. order by variablecount
Add Comment
Please, Sign In to add comment