本文介绍了如何自动每日执行查询 SQL Server?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想每天自动执行一些查询.我应该将它创建为存储过程还是有其他方法?这是我的疑问:

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:

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

推荐答案

在 sqlserver 中创建和安排作业

我更喜欢写 SP,但你可以直接写查询.

I prefer to write SPs , but you can write queries directly.

这篇关于如何自动每日执行查询 SQL Server?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 09:41