I am experiencing quite difficult problem and hope for your feedback. In my table I have a "Services"column in "MyData" table which contains names of my services. I have created SQL statement which should be executed via maintenance plan and get the minimum id value from one table and update "Value" column in "MyData" table:
declare @id int select @id = min(id) from MyTable where MyTime >= dateadd(MM, -12, DATEFROMPARTS(YEAR(getdate()),MONTH(getdate()),1)) update MyData set Value = @id where ColumnName= 'MyServiceName'
The statement works correctly, but I need to automate the things. Problem is, I have several Services and it will be inefficient to manually change "MyServicename" column in where clause each time it is needed to be updated. I ask for your advice, how can I automate the process of checking the "MyServiceName" in order to execute the statement for appropriate service? Sorry if it is written in too complicated way, but I hope could express the trouble I am expressing.