I have the next two Excel sheets that belong to the same excel file:
users:
----------------------------------------------
user_id name club fanatic_of
1 Joe Lakers
2 Frank Bulls
3 George Atlantic
------------------------------------------------
affiliatons
------------------------------------------------
user_id new_club date
1 Bulls 2023/11/01
1 Atlantic 2024/11/02
2 Lakers 2021/10/01
---------------------------------------------
I want to update users and the Excel SQL cmd looks like:
UDATE [users$] SET [fanatic_of] =
(CASE (SELECT COUNT(*)
FROM [affiliatons$]
WHERE [affiliatons$].[user_id] = [users$].[user_id]
)
WHEN 0 THEN [users$].club
WHEN 1 THEN [affiliatons$].new_club
ELSE "CHANGED MIND TOO MANY TIMES"
END)
Which in “Normal” SQL should be:
UDATE users SET fanatic_of = (
CASE (SELECT COUNT (*)
FROM affiliatons
WHERE affiliatons.user_id = users.user_id
)
WHEN 0 THEN users.club
WHEN 1 THEN affiliatons.new_club
ELSE "undecided"
END )
I am getting a message “Wrong automation error” from Excel VBA so I need to ask:
- Is my problem just an Excel VBA error? or is it also SQL?