selecting a range of columns in database [closed]
how can i select a range of columns in a database(Sqlserver eg..) i have name,id,and a dynami开发者_StackOverflowcally created columns named after dates..
do if i query from 1-1-2011 to 16-1-2011 ..the query should return all the dates between that range... excluding Sundays...
i am using access db with c#
so...i try is to select the columns from start date till we reach end date.. but how can it be done..(this removes Sundays too..:) )
also cant columns be selected using a index or something...like in arrays??
eg.schema is like this,,,,,column names are (id,name,'1-1-2011','2-1-2011','4-1-2011','6-1-2011','6-1-2011')..how do i display all rows from 2-1-2011 to 6-1-2011?
Try this
StringBuilder query = new StringBuilder("Select ID,Name ")
DateTime begindate=DateTime.Parse("2-1-2011");
DateTime enddate=DateTime.Parse("6-1-2011");
DateTime tempDate = begindate;
while(tempDate<=enddate )
{
if(tempDate.DayOfWeek!=DayOfWeek.Sunday)
{
if (tempDate==begindate )
{
query.Append(",");
}
query.Append(","+tempDate.ToString("dd-MM-yyyy"));
}
tempDate = tempDate.AddDays(1);
}
query.Append(" From table Name");
then execute the generated select statement.
精彩评论