Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 267255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:31:15+00:00 2026-05-11T23:31:15+00:00

Table like datetime a1 b1 x2 … 07-01-2009 13:10 8 9 10 07-01-2009 13:11

  • 0

Table like

datetime          a1   b1   x2 ...  
07-01-2009 13:10   8    9    10  
07-01-2009 13:11   8    8    2  
07-01-2009 13:12   9    1    1    

1 row per second for a whole day (=86400 rows); ~40 columns; all same format
I’m looking for a way to retrieve a max value and the time for a column to specify.

I’m looking for a way to retrive a max value and the according time for a column to specify within a timeframe.

Something like

Select top 1 time,a1 from table
    where (datetime>=begin and datetime<end) 
    order by a1 desc   

will work but I cannot use the column as a parameter.

A LINQ solution or a SP would be great.

Do I have to worry about performance when sorting a whole dataset to retrieve a max value? Maybe MAX function will be faster.

UPDATE

I tried to implement it the dynamic linq way, like Timothy (tvanfossen) suggested

Dim q2 = context.table _
  .Where("t >= @0 AND t < @1", begin, end) _
  .OrderBy("@0 desc", col) _
  .Take(1) _
  .Select(col)

BUT this returns the first value in the table.
This returns the first value in the time frame and not the max value. Looking at the SQL profiler I see that there is no ORDER clause.
Any idea?

UPDATE 2
For some reason the substitution value does not work in the orderby clause.
.OrderBY (col + ” desc”) works

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T23:31:15+00:00Added an answer on May 11, 2026 at 11:31 pm

    If you want the column name to be dynamic, you might want to use Dynamic Linq from the VS2008 code samples. Then you can specify the name of the column to sort by.

    var query = context.table
                       .Where( t = t.begin <= date && date < t.end )
                       .OrderBy( "a1 desc" )
                       .Take(1)
                       .SingleOrDefault();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to get table metadata for all table columns. Like type string(varchar2)/int/float/datetime and
I have 7 rows in my table like Date1,Date2... they´re all dateTime, and i
I've a table like (I am omitting unnecessary columns) id:int | name:string | ts:DateTime
Using MySQL syntax and having a table with a row like: mydate DATETIME NULL,
Table structure- int PrimaryKey DateTime Date int Price What I would like to do
I have a table that looks like this: ---------------------- | DateTime | Value |
I have datetime in my table like this 01.08.2012 14:20 22.10.2012 10:02 i enter
Suppose I have a table like: Tab(MyDate datetime null, MyIs bit null, ...) Then
I have a LoginTime table like this: id | user_id | datetime 1 |
I have a LoginTime table like this: id | user_id | datetime 1 |

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.