Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change Query to Update 2 1

Status
Not open for further replies.

mentasses

Technical User
Mar 23, 2004
29
GB
I have a SELECT query

SELECT a.STAFFNO,a.REGION,a.DEPARTMENT,
LEFT(REGION,3)AS REGCODE,
LEFT (DEPARTMENT,4)AS DEPTCODE
(DEPTCODE + REGCODE) AS ACCODE
(DEPTCODE + REGCODE) AS COSTCNTRE
FROM ELYOSERVICES.dbo MASTER a
WHERE STATUS ='Active'

Users enter REGION and DEPARTMENT from a pick list for each Employee in the database. The formate is
REGION: adc - Midlands - Birmingham
DEPARTMENT: 1234 - Engineer

I need to capture just the first part of each, join them and update ACCODE and COSTCNTRE (1234adc)in the same database.

I am not sure how to change the query to update these fields, can anyone help?
 
Code:
UPDATE ELYOSERVICES.dbo.MASTER 
SET ACCODE = LEFT(DEPARTMENT,4)+LEFT(REGION,3),
    COSTCETRE = LEFT(DEPARTMENT,4)+LEFT(REGION,3)
WHERE STATUS ='Active'
[code]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top