Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an integer variable called x. I want a select query with creating x number of empty columns. How can I write this ? I can't use loop because I have to use this query as a c# string in my application.

as an example I can create one empty column as below

SQL
SELECT a.str_typeid, a.str_typename, a.str_status, a.strlst_user,
       a.dt_entdate, '' as empty_column
  FROM ref_productitem_disc a



Then I want use x to number of empty columns. In other words , how can I create x number of empty columns?
Posted
Updated 12-Jan-15 22:24pm
v2

1 solution

Your c# code to construct the emply column.

C#
public static string show(int r)
        {
            if (r > 0)
            {
                List<string> list = new List<string>();
                for (int i = 0; i < r; i++)
                {
                    list.Add("'' as emplty_column" + (i + 1));
                }

                return string.Join(",", list);
            }
            return "";
        }


VB
string val = show(5);
            string strquery = @"SELECT a.str_typeid, a.str_typename, a.str_status, a.strlst_user,
       a.dt_entdate" + ((val == "") ? "" : ","+val) + @"
  FROM ref_productitem_disc a";


Your strQuery will the query.
 
Share this answer
 
Comments
Prabhani Panamulla 13-Jan-15 5:06am    
thanxx for the help :)
Praveen Kumar Upadhyay 13-Jan-15 5:11am    
welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900