我已经在批处理文件中编写了 foll sql 查询以从远程服务器获取结果。
SQLCMD -S "ServerName -U "uer" -P "Pass" -W -d"Interface" -Q"select LEFT(Zone_Prefix,5)+case when RIGHT(Zone_prefix,1)='N' then '_NORTH_WING' ELSE '_SOUTH_WING' END AS [Zone Name],cnt as [Zone Count] from ( SELECT LEFT([Zone Name], 6) AS Zone_Prefix,SUM([Zone Count]) cnt FROM [Interface].[dbo].[VwZoneCount] WHERE [Zone Name] IN ('EB2GFNMZ','EB2GFSMZ','EB2GFNZ1','EB2GFSZ1','EB21FNZ1','EB21FSMZ','EB21FSZ1','EB22FNZ1','EB22FSZ1','EB22FSMZ','EB23FNMZ','EB23FNZ1','EB23FNZ2','EB23FNZ3','EB23FSMZ','EB23FSZ1','EB23FSZ2','EB24FNMZ','EB24FNZ1','EB24FSMZ','EB24FSZ1','EB25FNMZ','EB25FNZ1','EB25FSMZ','EB25FSZ1','EB26FNMZ','EB26FNZ1','EB26FSMZ','EB26FSZ1','EB27FNZ1','EB27FSMZ') GROUP BY LEFT([Zone Name], 6))tbl" -s" " -o"Output_hvac.xls"
我使用 task scheduler 每 4 小时执行一次此查询。目前,每次执行的结果都会被覆盖。每次执行后,我都需要将新结果附加或存储在带有Time Stamp的不同文件中。我主要关心的是放置一个时间戳并保留所有以前执行的数据。
谢谢