RE: Simple Problem - Simple Solution?

Tech-Archive recommends: Fix windows errors by optimizing your registry

From: Nigel Rivett (NigelRivett_at_discussions.microsoft.com)
Date: 12/20/04


Date: Mon, 20 Dec 2004 08:07:03 -0800

well a loop doesn't take much code - something like

declare @plan_id varchar(36)
select @plan_id = '00000000-0000-0000-0000-000000000000'
while @plan_id < (select max(convert(varchar(36),plan_id)) from
msdb..sysdbmaintplans)
begin
        select @plan_id = min(convert(varchar(36),plan_id)) from
msdb..sysdbmaintplans where convert(varchar(36),plan_id) > @plan_id
        exec sp_delete_maintenance_plan @plan_id = @plan_id
end

"DBA72" wrote:

> I want to execute a stored proc. multiple times with the least amount of code.
> For example, I want to execute: "sp_delete_maintenance_plan @plan_id = xxx"
>
> from the following list:
> "SELECT plan_id
> FROM msdb.dbo.sysdbmaintplans
> WHERE plan_id <>'00000000-0000-0000-0000-000000000000'
> GO"
>
> Is it possible to do this without using a loop or a cursor?
>