我有一些想每天自动执行的查询。我应该将它创建为存储过程还是有其他方法?这是我的查询:
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