title: How to auto daily execute queries SQL Server?
body: <p>I have some queries that I want to execute every day automatically. Should I create it as stored procedure or there are another ways? here is my queries:</p>
  
  <pre><code>declare @tanggal_1 varchar(50)
  
  set @tanggal_1 = (select top 1 ltrim(rtrim(cast(numweek as char)))+'-('+rangeweek+')' from tbl_weeklyflash_id where year([date]) = year(getdate()) order by numweek desc)
  
  TRUNCATE table mytable
  GO
  INSERT INTO mytable (field1, field2, field3)
  EXEC my_store_procedure @tanggal_1
  GO
  UPDATE mytable SET 
   [field4] = isnull(((nullif([cm1pl2],0)/nullif([cm1pl2_per],0))*100),0)
  ,[field5] = isnull(((nullif([cm1pl1],0)/nullif([cm1pl1_per],0))*100),0)
  ,[field6] = isnull(((nullif([cm1_cost_value],0)/nullif([cm1_cost_per],0))*100),0)
  GO
  </code></pre>