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 |
KyleFerence
Starting Member
4 Posts |
Posted - 2014-12-18 : 19:06:37
|
Hello. I have a query from an ACCESS database that I want to move over to SISS, but it will not run and says the syntax is wrong. Does anyone know how to correct the syntax on the query below? ACCESS Query: UPDATE PROPERTYOWNERS INNER JOIN PROPERTYOWNERS AS PROPERTYOWNERS_1 ON PROPERTYOWNERS.gislink = PROPERTYOWNERS_1.gislink SET PROPERTYOWNERS.mixedownership = "MIXED"WHERE (((PROPERTYOWNERS_1.secondaryclass)<>[PROPERTYOWNERS]![secondaryclass]));Thanks for your help. |
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-12-18 : 19:08:54
|
I don't know how to convert your WHERE clause, but here is the rest:UPDATE PROPERTYOWNERS SET mixedownership = 'MIXED'FROM PROPERTYOWNERSJOIN PROPERTYOWNERS AS PROPERTYOWNERS_1ON PROPERTYOWNERS.gislink = PROPERTYOWNERS_1.gislink What does this do: [PROPERTYOWNERS]![secondaryclass]Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
KyleFerence
Starting Member
4 Posts |
Posted - 2014-12-19 : 11:17:54
|
The first part works :) I think the WHERE clause was wrong in the ACCESS query. I think it should read (PROPERTYOWNERS_1.secondaryclass)<>(PROPERTYOWNERS.secondaryclass); but it still does not work.The where clause is changing the MEMBERSHIP field to "MIXED" where the ownership is mixed in the SECONDARYCLASS. So if I have two owners for the same property I want it to read MIXED. So the WHERE clause is looking for two owners.eg:gislink | secondaryclass | mixdownership121 | Private | MIXED 121 | Provincial | MIXED488 | Private | NULL488 | Private | NULLSo the WHERE clause is going to change the gislink to MIXED as it has two owners in the secondaryclass. Thanks for all your help :) |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-12-19 : 12:13:35
|
Maybe this?UPDATE PROPERTYOWNERS SET mixedownership = 'MIXED'FROM PROPERTYOWNERSJOIN PROPERTYOWNERS AS PROPERTYOWNERS_1ON PROPERTYOWNERS.gislink = PROPERTYOWNERS_1.gislink AND PROPERTYOWNERS_1.secondaryclass <> PROPERTYOWNERS.secondaryclass;Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
KyleFerence
Starting Member
4 Posts |
Posted - 2014-12-19 : 12:37:56
|
I solved my problem.UPDATE PROPERTYOWNERS SET mixedownership = 'MIXED'WHERE PROPERTYOWNERS.gislink IN (SELECT PROPERTYOWNERS.gislinkFROM PROPERTYOWNERS INNER JOIN PROPERTYOWNERS AS PROPERTYOWNERS_1 ON PROPERTYOWNERS.gislink = PROPERTYOWNERS_1.gislinkWHERE PROPERTYOWNERS_1.secondaryclass <> PROPERTYOWNERS.secondaryclass) |
|
|
KyleFerence
Starting Member
4 Posts |
Posted - 2014-12-19 : 12:38:53
|
Thanks for your help :) |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-12-19 : 12:40:29
|
I don't understand why you switched it to a subquery. It is less efficient. At the very least, I'd switch your code to use WHERE EXISTS rather than IN.Tara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
|
|
|