Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
Harry C
Posting Yak Master
148 Posts |
Posted - 2006-05-24 : 23:45:27
|
| UPDATE #TempTable SET BackGroundColor = '#ffff99' WHERE (CompletedDate IS NULL AND PlanCompletionDate > @Date AND PlanCompletionDate > EstimatedCompletionDate AND CorrectiveActionTypeID IS NULL)What I need to do is in this update Take the value of the first row that BackGroundColor = '#ffff99' and update ALL rows AFTER IT to BackGroundColor = '#ffff99' as well. Any thoughts on how I could do that? ThanksHere is my ddlCREATE TABLE [dbo].[ProjectEvent]( [ProjectID] [int] NOT NULL, [EventID] [int] NOT NULL, [EventOrder] [int] NULL, [CorrectiveActionTypeID] [int] NULL, [EstimatedCompletionDate] [datetime] NULL, [CompletedDate] [datetime] NULL, [ModifiedBy] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [CompletedBy] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [LeadTime] [int] NOT NULL, [CorrectiveActionNote] [varchar](1000) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [CorrectiveActionCost] [money] NULL, [CorrectiveActionPartyResponsible] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL, [PlanCompletionDate] [datetime] NULL, CONSTRAINT [PK__ProjectEvent__48EFCE0F] PRIMARY KEY CLUSTERED ( [ProjectID] ASC, [EventID] ASC)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]) ON [PRIMARY]GOHarry C |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-05-24 : 23:52:31
|
It's not quite clear what you want. Can you post some sample data and the result that you want ? KH |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-05-25 : 01:32:05
|
| Somthing like this ?? UPDATE #TempTable SET BackGroundColor = (Select Top 1 BackGroundColor From #TempTable Where BackGroundColor Is Not Null Order by Pk)WHERE (CompletedDate IS NULL AND PlanCompletionDate > @DateAND PlanCompletionDate > EstimatedCompletionDate AND CorrectiveActionTypeID IS NULL)If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them. |
 |
|
|
Harry C
Posting Yak Master
148 Posts |
Posted - 2006-05-25 : 13:26:23
|
| Something like this... But all in one query, if possibleUPDATE #TempTable SET BackGroundColor = '#ffff99' WHERE CompletedDate IS NULL AND PlanCompletionDate > @Date AND PlanCompletionDate > EstimatedCompletionDate AND CorrectiveActionTypeID IS NULLUPDATE #TempTable SET BackGroundColor = '#ffff99'WHERE EventOrder > ( Select MIN(EventOrder) FROM #TempTable WHERE BackGroundColor = '#ffff99' ) AND CorrectiveActionTypeID IS NULLI got this from another developerUPDATE #TempTable SET BackGroundColor = '#ffff99'WHERE EventOrder >= ( SELECT MIN(EventOrder) WHERE CompletedDate IS NULL AND PlanCompletionDate > @Date AND PlanCompletionDate > EstimatedCompletionDate AND CorrectiveActionTypeID IS NULL ) But it throws an error"An aggregate may not appear in the WHERE clause unless it is in a subquery contained in a HAVING clause or a select list, and the column being aggregated is an outer reference. " |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-05-27 : 02:00:24
|
Try this .. UPDATE #TempTable SET BackGroundColor = '#ffff99'WHERE EventOrder >= (SELECT MIN(EventOrder) From #TempTable Having CompletedDate IS NULLAND PlanCompletionDate > @DateAND PlanCompletionDate > EstimatedCompletionDateAND CorrectiveActionTypeID IS NULL ) If Debugging is the process of removing Bugs then i Guess programming should be process of Adding them. |
 |
|
|
|
|
|
|
|