Link to home
Start Free TrialLog in
Avatar of Icebreak
Icebreak

asked on

How to UPDATE a field using INNER JOIN...Access query works. Need to convert to SQL Server.

Its been a long time since Ive been to EE.  The place looks great.

Im very new to SQL server.  I'm using Microsoft SQL Enterprise Manager Version: 8.0

The task at hand is a data conversion.  One part is to make the contents in a field (cLLCClss) that is NB or NA become NP.  Part of doing this will be deleting one of two entitys (nLLCEntId) records that has two records with these two classes, NB and NA.  The one with NA stays and the one with NB goes away.

So I thought Id update another field (cLLCInsUser) in the records that meet the criteria for deletion with ZZ  Then I could delete those records based on ZZ as the criteria.

I created a table (tblLLicenseClassNANB) that contains those records with only one field (nLLCEntId) in it.  I join that to the actual table (dbo_tblLLicenseClass) that will be the target of the update.  In select, it returns what I want.  When I put the NB in as criteria it returns the exact records I want to update.

This works in Access and looks like this:

UPDATE tblLLicenseClassNANB INNER JOIN dbo_tblLLicenseClass ON tblLLicenseClassNANB.nLLCEntId = dbo_tblLLicenseClass.nLLCEntId SET dbo_tblLLicenseClass.cLLCInsUser = "ZZ"
WHERE (((dbo_tblLLicenseClass.cLLCClss)="NB"));

In SQL the select statement looks like this:

SELECT     *, tblLLicenseClass.cLLCClss AS Expr1
FROM         tblLLicenseClass INNER JOIN
                      tblLLicenseClassNANB ON tblLLicenseClass.nLLCEntId = tblLLicenseClassNANB.nLLCEntId
WHERE     (tblLLicenseClass.cLLCClss = 'NB')

I attempted updating it this way but it returns an error (near INNER):

UPDATE    tblLLicenseClass INNER JOIN
                      tblLLicenseClassNANB ON tblLLicenseClass.nLLCEntId = tblLLicenseClassNANB.nLLCEntId
SET              cLLCInsUser = 'ZZ'
WHERE     (tblLLicenseClass.cLLCClss = 'NB')

Would someone tell me how to update this field using the INNER JOIN or convert the Access SQL statement to a SQL Server SQL statement?

I hope I'm posting the question in the right place.  And I don't remember if 100 pts. is about right.

TIA

ASKER CERTIFIED SOLUTION
Avatar of dqmq
dqmq
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Icebreak
Icebreak

ASKER

I got "The Query Designer does not support the Optional FROM clause SQL construct."

I may have posed the question wrong.  I'm in SQL Server Enterprise Manager in a query.

Anyway, I just ran it and it shifted the spacing around like this:

UPDATE    tblLLicenseClass
SET              cLLCInsUser = 'ZZ'
FROM         tblLLicenseClass INNER JOIN
                      tblLLicenseClassNANB ON tblLLicenseClass.nLLCEntId = tblLLicenseClassNANB.nLLCEntId
WHERE     (tblLLicenseClass.cLLCClss = 'NB')

And it ran perfectly.

Thanks a lot.  That will really get me down the road.  Very much appreciated.

I'll go tap that 'accept as answer' button now.
Outstanding!