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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Update field using Max

Author  Topic 

Pitchfork
Starting Member

4 Posts

Posted - 2009-12-07 : 12:29:30
I have a query that returns the info I need but need to Update a field:
SELECT Job_Operation.Job, Max(Job_Operation.Sequence) AS MaxOfSequence, Job_Operation.Operation_Service
FROM Job_Operation
WHERE (((Job_Operation.Work_Center)='QC') AND ((Job_Operation.Job) Like 'F%') AND ((Job_Operation.Status)='O'))
GROUP BY Job_Operation.Job, Job_Operation.Operation_Service;

I need to Update the Job_Operation.Operation_Service field to PPAP.

I would like to do this so I can schedule it to run every night using SQL Server Agent and Jobs to ran it.

Thanks,
Greg
Impulse MFG

X002548
Not Just a Number

15586 Posts

Posted - 2009-12-07 : 12:31:50
Why?

Create a view



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Pitchfork
Starting Member

4 Posts

Posted - 2009-12-07 : 13:17:26
The code is from my view called QCOp2PPAP. Can I from the View put a statement to Update the Operation_Service field to PPAP?
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2009-12-07 : 13:19:58
What I am saying is, why create a column with derived data that will be stale the second after you run the update?

Just create a view with the MAX and join to it when you need the data


???



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Pitchfork
Starting Member

4 Posts

Posted - 2009-12-07 : 13:44:40
The point is I needed to find the max to find the line I need to change. The view or query I am showing is the info I need to change.
Job 12345
has routings steps that can be dups and I need to change the last QC Seq Work_Center
0 Prog Free
1 Prod Cond
2 Saw
3 QC
4 WeldMig
5 QC
6 PowderPaint
7 QC
8 TransFG
Go to Top of Page

Pitchfork
Starting Member

4 Posts

Posted - 2009-12-07 : 14:59:01
Ok my view is shown below when I get this view I then need to change the column Operation_Service data to read: PPAP

USE [Training]
GO
/****** Object: View [dbo].[QCOp2PPAP] Script Date: 12/07/2009 14:54:31 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER VIEW [dbo].[QCOp2PPAP]
AS
SELECT Job, Operation_Service, MAX(Sequence) AS MaxOfSequence
FROM dbo.Job_Operation
WHERE (Job LIKE 'F%') AND (Work_Center = 'QC') AND (Operation_Service <> 'PPAP') and (Status = 'O' OR
Status = 'S')
GROUP BY Job, Operation_Service
Go to Top of Page
   

- Advertisement -