Creating a Dynamic Select Statement from 2 databases on the same server Can someone improve on my method for creating union select views from 2 databases located within the same server in C#, here is the code for the method:

public override DataSet GetDynamicReportData(string strSQL) {

        var sbSQL = new StringBuilder(strSQL);
        var finalQueryStr = new StringBuilder(strSQL);

        sbSQL.Replace("SELECT DISTINCT ", "");

        var iamNEAS3 =
            new StringBuilder(" UNION SELECT DISTINCT ");

        var queryColumns = sbSQL.ToString().Split(',');

        for (var i = 0; i &lt;= queryColumns.Length - 1; i++) {

            iamNEAS3.Append(queryColumns[i]);

            if (i &lt; queryColumns.Length - 1) {
                iamNEAS3.Append(", ");
            } else if (i == queryColumns.Length - 1) {

                var appendMagic =
                    queryColumns[i].Replace(
                        "From [dbo].[vw_Classified_ApplicationsFiles]",
                        "FROM [project_phoenix].[dbo].[vw_Classified_ApplicationFiles]")

                iamNEAS3.Append(appendMagic);

                // Systematic removal; thank you!
                iamNEAS3.Replace(queryColumns[i], "");
            }
        }

        finalQueryStr.Append(iamNEAS3);

        return DALDynamicReport.GetData(finalQueryStr.ToString());
    }


Now it receives a string parameter where

strSQL = "Select Distinct [Row1], [Row2], [Row3], [Row4] From [project_mongoose].[dbo].[vw_Classified_ApplicationsFiles] where [Row2] &lt;= 200". 


I know my programming skills are limited, but is there a way to not code this by hand like I did?
The first thing you should improve is to split this method into two methods, one for parsing the input string and one for  building a new query. Doing both in the same method isn't a good practice. 

This means that the first method should return a collection of columns that the other one consumes.