Skip to content
Advertisement

Port MySQL script to MS SQL -> simultaneous data asignement and retrieval

I have been trying to make this work for hours but I can’t really find a way to do it. I have a MySQL script that I need to migrate to MS SQL 2014, however, I can’t seem to make it work. As far as I have understood, the big issue is that MySQL allows this kind of instructions:

where you assign a value at the same time you retrieve data, but MS SQL does not.

I have a relatively big script which has that issue:

Can anybody point me in the direction of what I have to do to recreate the code in MS SQL? Thank you all in advance

Advertisement

Answer

My big problem lied in this line:

but as Gordon Linoff pointed me. this problem could be solved with window functions, the right translation od that function is:

it ended up being easier than I thought
Thanks a lot and I hope it can help others as well

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement