I’m having a problem when i refactoring the legacy join syntax to ANSI join syntax’s, because most of the procedures in our database is using the legacy join. this is the code I need to change it to use the SQL ‘JOIN’ syntax rather than the normal legacy join. can any one suggest me how it can be done?
select
a.userkey,
a.username,
c.monthd ,
b.currencykey
from
#users a,
#invoicedata b,
#revdate c
where
(a.userkey >= b.userkey or a.userkey <= b.userkey)
and b.idate between c.startdate and c.enddate
group by
a.userkey,
a.username,
c.monthd,
b.currencykey
order by c.id,a.username,b.currencykey
This part
(a.userkey >= b.userkey or a.userkey <= b.userkey)doesn’t seem correct and you can’torder bycolumns (at least withoutagregatefunctions) that aren’t in thegroup by.So, possibly something like this:
I’ve also replaced nested joins with inner joins but that wasn’t necessary 🙂
On the other hand, you may want a cross join: