Skip to content

Tag: loops

While loop function union function end

I want to loop the code shown below. I would like to use the [getpublicholidays] function for a variable number of years and merge them (union). Unfortunately I don’t know how to use the function in a loop with union. Can someone help? Answer If you are looping for X years, each time you loop to a new y…

SQL query with loop to collect 14 day averages

I am a python user, new to SQL. I am trying to make a new table that is the average of the “NumberValue” column between two dates from “RecordDate” column, and slide that date range so that the new table has columns “average” that is the average of “NumberValue”…

Iterate through a list of servers in SQL Server

I have a script similar to below and get: Could not find server ‘@CURSERVER’ in sys.servers. Verify that the correct server name was specified. If necessary, execute the stored procedure sp_addlinkedserver to add the server to sys.servers. I am trying to get SQL Server Agent jobs from all linked s…