Explore BrainMass

Explore BrainMass

    SQL script to sort numbers across columns

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    a user can add column to the table ,where the program sort them and display them sorted ,with sort i mean by row not order by;
    order by is easy but sorting rows is harder,the difficultly comes with the fact that the user can add colums where the program should do the sort and display them in gridview.

    attach document which describe the question more

    © BrainMass Inc. brainmass.com October 10, 2019, 8:10 am ad1c9bdddf


    Solution Preview

    Dear student, please find attached SQL scripts that gives you the results as you have requested.

    The solution is based on usage of SQL user-defined function which is named UF_MY_SORT_COLUMNS which takes as parameters integers and returns a string of these numbers sorted.

    Please replace [BM] with the name of your ...

    Solution Summary

    The sql script will create a table with 4 columns and a user defined function that can take in these 4 values and produce a string where numbers are sorted in ascending order. Another query is provided that makes usage of this user defined function to produce an extra 5th column with sorted row results. The scripts are made in such a way that adding 5th, 6th, etc column should be an easy task.