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

  • Home
  • SEARCH
  • 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 113205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T02:39:56+00:00 2026-05-11T02:39:56+00:00

I have a database that has a vessel pressure that is trended every 30

  • 0

I have a database that has a vessel pressure that is trended every 30 seconds. I would like to be able to retrieve a recording at a specific time of day for a number of days in the past. I am not able to base this on the server as a Stored Procedure or a View – I only have read access. I have created a routine that works for 17 days in the past but I would like it to be able to give a few months data. I could I guess just make repeated calls from the c# app, but that seems even more inefficient than the method I am using now. Does anyone have any recommendations.

Brad

declare @DeadBand DateTime declare @EndDate DateTime declare @End varchar(50) declare @Start varchar(50) declare @Temp varchar(50) declare @NumberDays int declare @dec int  declare @InnerSqlQry as varchar(8000) declare @SqlQry as varchar(8000) SET @NumberDays = 5 SET @dec = @NumberDays SET @Start = CONVERT(Varchar(30),dateadd(dd,-@NumberDays,GetDate())) SET @End = CONVERT(Varchar(30),GetDate()) SET @DeadBand= + CONVERT(Varchar(30),dateadd(ss,90,@Start))      SET @Width = + CONVERT(Varchar(30),dateadd(ss,90,@Start)) WHILE (@dec >= 1)     BEGIN                    set @InnerSqlQry = ' Select DateTime,ACMKWHYTD_1 From WideHistory        Where  Datetime >='''+convert(varchar(30), @Start ,120) +''' AND Datetime <= '''+convert(varchar(30),@DeadBand,120) +''' and wwResolution =60000 and wwRetrievalMode = 'cyclic' '              if(@dec = 1)                     begin                             set @SqlQry = @SqlQry+ N' Select top 1 * from openquery(INSQL,''' + REPLACE(@InnerSqlQry, '''', '''''') + ''' )'                     end              if((@dec > 1) and (@dec < @NumberDays))                     begin                             set @SqlQry = @SqlQry+ N' Select top 1 * from openquery(INSQL,''' + REPLACE(@InnerSqlQry, '''', '''''') + ''' ) union '                     end              if(@dec = @NumberDays)                     begin                             set @SqlQry = N' Select top 1 * from openquery(INSQL,''' + REPLACE(@InnerSqlQry, '''', '''''') + ''' ) union '                     end              set @dec = @dec - 1              SET @Start = CONVERT(Varchar(30),dateadd(dd,-@dec,GetDate()))             SET @DeadBand= + CONVERT(Varchar(30),dateadd(ss,90,@Start))      END     print(@sqlQry)     exec(@sqlQry) 
  • 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. 2026-05-11T02:39:57+00:00Added an answer on May 11, 2026 at 2:39 am

    I’ve seen quite a few tricks for converting a DATETIME into ‘just a time’. Infact where I work there was quite some time spent finding the fastest. What people seem to forget is that ‘shortest code’ is not always fastest, and often includes Implicit type conversions hidden away. The fastest we came up with is…

    DATEADD(DAY, DATEDIFF(MINUTE, 0, ), 0)

    The reason I mention it is that once you have the time component, everything becomes easier and allows for easier code changes for subtly different needs.

    DECLARE     @start_date    DATETIME,     @end_date      DATETIME,     @chosen_time   DATETIME SELECT     @start_date    = '2009 Jan 05 00:00',     @end_date      = '2009 Jan 12 00:00',     @chosen_time   = '1900 Jan 01 17:30'   -- '1900 Jan 01' is day 0  SELECT     <whatever> FROM     WideHistory   WHERE         [WideHistory].DateTime >= @start_date     AND [WideHistory].DateTime <  @end_date     AND DATEADD(DAY, DATEDIFF(MINUTE, 0, [WideHistory].DateTime), 0) = @chosen_time 

    One could easily adapt that to several key times of day, or a range of times, etc, etc…

    EDIT:

    As mentioned in comments to this answer, a change to the database structure would also benefit here. Having a DATE field as well as a TIME field. Often superfluous, but in this case could be beneficial.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 75k
  • Answers 75k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer To add any control to a parent control: MyControl :=… May 11, 2026 at 2:53 pm
  • added an answer There's the Java based Apache Batik SVG toolkit. In a… May 11, 2026 at 2:53 pm
  • added an answer I doubt that this would be possible. A solution consists… May 11, 2026 at 2:53 pm

Related Questions

I have a database that is part of a Merge Replication scheme that has
I have a database structure that has a Person table which contains fields such
Suppose I have a database table that has a timedate column of the last
I have a SQL Server database that has a huge proliferation of stored procedures.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.