Convert mysql stored procedure to mssql

I need to use a dynamic order query in mysql and I have successfully achieved this using string concatenation in mysql like this:

set @stmt_text: = concat ('select * from abc order by', sorder );

prepare stmt_handle from @stmt_text;

execute stmt_handle;

deallocate prepare stmt_handle;

I need a similar conversion in mssql

Any ideas?

0


source to share


1 answer


Yes, just run it like this:

execute ('select * from abc order by ' + @sorder);

      



But don't forget that you need to check the sorder variable if you get it via user input (to stop sql injections)

+2


source







All Articles