开发者

selecting a range of columns in database [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜