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.nLLCE ntId = dbo_tblLLicenseClass.nLLCE ntId SET dbo_tblLLicenseClass.cLLCI nsUser = "ZZ"
WHERE (((dbo_tblLLicenseClass.cL LCClss)="N B"));
In SQL the select statement looks like this:
SELECT *, tblLLicenseClass.cLLCClss AS Expr1
FROM tblLLicenseClass INNER JOIN
tblLLicenseClassNANB ON tblLLicenseClass.nLLCEntId = tblLLicenseClassNANB.nLLCE ntId
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.nLLCE ntId
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
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.nLLCE
WHERE (((dbo_tblLLicenseClass.cL
In SQL the select statement looks like this:
SELECT *, tblLLicenseClass.cLLCClss AS Expr1
FROM tblLLicenseClass INNER JOIN
tblLLicenseClassNANB ON tblLLicenseClass.nLLCEntId
WHERE (tblLLicenseClass.cLLCClss
I attempted updating it this way but it returns an error (near INNER):
UPDATE tblLLicenseClass INNER JOIN
tblLLicenseClassNANB ON tblLLicenseClass.nLLCEntId
SET cLLCInsUser = 'ZZ'
WHERE (tblLLicenseClass.cLLCClss
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Outstanding!
ASKER
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
WHERE (tblLLicenseClass.cLLCClss
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.