I searched the forum, but I could not find what I was looking for. I know I've seen it on here before. What I want to do is if "IsRecurring = 1" then calculate the NextExecution, and update the Next Execution field. I have the calculation stuff figured out. If IsRecurring = 0 then I want to set IsDisabled = 1.I know I can do this with some If statements etc, but I think there's a way to do this in a single UPDATE statement and maybe make it easier to read and understand.Here is what I have so far: CREATE TABLE [#Task] ( [TaskID] [int] IDENTITY (1, 1) NOT NULL , [TaskName] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [TaskInterval] [varchar] (4) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [IntervalUnit] [int] NOT NULL , [NextExecution] [datetime] NULL , [LastExecution] [datetime] NULL , [IsDisabled] [bit] NOT NULL CONSTRAINT [DF_Task_IsDisabled] DEFAULT (0), [IsRecurring] [bit] NOT NULL CONSTRAINT [DF_Task_IsRecurring] DEFAULT (1), [HasErrored] [bit] NOT NULL CONSTRAINT [DF_Task_HasErrored] DEFAULT (0), [ErrorText] [varchar] (7000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [Cre_Date] [datetime] NOT NULL CONSTRAINT [DF_Task_Cre_Date] DEFAULT (getdate()), [Cng_Date] [datetime] NOT NULL CONSTRAINT [DF_Task_Cng_Date] DEFAULT (getdate()),) INSERT INTO #Task(TaskName, TaskInterval, IntervalUnit, NextExecution, IsRecurring)values('One Time Task', 'dd', 0, '4/23/2003', 0)DECLARE @TaskID INTSELECT @TaskID = @@IDENTITYselect * from task--START PSUDEO CODEUPDATE TASK WHEN IsRecurring = 1 THEN SET NextExecution = '5/1/2003', Cng_Date = GETDATE() WHEN IsRecurring = 0 THEN SET IsDisabled = 1, Cng_Date = GetDate()WHERE TaskID = @TaskID--END PSUDEO CODEselect * from taskdrop table #task Michael
<Yoda>Use the Search page you must. Find the answer you will.</Yoda>