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 7036035
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:22:32+00:00 2026-05-28T01:22:32+00:00

SQL Server 2005. Table schema is MarketdataID, Datatype, Date, Source, Coordinate, Value. PK is

  • 0

SQL Server 2005. Table schema is MarketdataID, Datatype, Date, Source, Coordinate, Value. PK is everything except Value. Data may be available from multiple sources and may not be available for the given date; I want to get the most recent date before the given date, and only one source per date.

SELECT top 1 [Source], [Date] FROM Market
WHERE MarketDataID = ?
AND DataType = ?
AND [Date] <= ?
order by [date] desc, [source]

then use the returned date and source in this query:

SELECT [Coordinate], [Value] FROM Market
WHERE MarketDataID = ?
AND DataType = ?
AND [Date] = ?
AND [Source] = ?
ORDER BY [coordinate]
  • 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-28T01:22:33+00:00Added an answer on May 28, 2026 at 1:22 am
    SELECT [Coordinate], [Value]
      FROM Market AS m0
      JOIN (SELECT TOP 1 m2.[Source], m2.[Date], m2.MarketDataID, m2.DataType
              FROM Market AS m2
             WHERE m2.MarketDataID = ?
               AND m2.DataType = ?
               AND m2.[Date] <= ?
               ORDER BY m2.[Date] DESC, m2.[Source]
           ) AS m1
        ON m0.[Source]     = m1.[Source]
       AND m0.[Date]       = m1.[Date]
       AND m0.MarketDataID = m1.MarketDataID
       AND m0.DataType     = m1.DataType
     ORDER BY [coordinate]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a SQL Server 2005 data-mart star schema with the usual fact and
I've got the following table schema in SQL Server 2005 and I'd like to
I've got data in a SQL Server 2005 table that I need to insert
I have a SQL Server 2005 table like this: create table Taxonomy( CategoryId integer
I have an SQL Server 2005 table that has a varchar(250) field which contains
I have a table with primary key in my MS SQL Server 2005 table.
Is it possible to force a column in a SQL Server 2005 table to
I have a nullable DateTime column in my SQL Server 2005 table called DateTimeDeleted.
I have an ADOQuery that inserts a record to SQL Server 2005 table that
I want to check whether a Tag (Case-Sensitive) exists in SQL Server 2005 table

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.