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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:44:04+00:00 2026-05-27T22:44:04+00:00

My last question on this same cte query was answered so quickly, I thought

  • 0

My last question on this same cte query was answered so quickly, I thought I’d bounce this next one off you sql gurus. If I could go over my basic logic, then show my code and syntax error, any help would be greatly appreciated..

I have three tables for a stock trading system: a symbols table: as the name suggests it’s a list of ticker symbols, a daily pricing/ volume table: again, as- described, and each record has a date field and symbol field as well as the pricing info, and lastly a trading dates table: the reference for all trading dates in our query.

I’d like to return a recordset with two fields: a symbol and a date. The pair represents all trading dates and symbols that don’t have corresponding pricing/ vol data for that symbol in the pricing volume table. Make sense? On my query, I’m getting the error message: “The multi-part identifier “Symb.Symbol” could not be bound.” Here’s my cte query:

WITH Symb AS
(
     SELECT Symbol
     FROM tblSymbolsMain
),

DatesNotNeeded AS
(
     SELECT Date
     FROM tblDailyPricingAndVol
     WHERE (tblDailyPricingAndVol.Symbol = Symb.Symbol)
),

WideDateRange AS
(
     SELECT TradingDate
     FROM tblTradingDays
     WHERE (TradingDate >= dbo.NextAvailableDataDownloadDateTime()) AND (TradingDate <= dbo.LatestAvailableDataDownloadDateTime())
),

DatesNeeded AS
(
     SELECT TradingDate
     FROM WideDateRange wdr
     WHERE NOT EXISTS (SELECT * FROM DatesNotNeeded)
)

SELECT Symb.Symbol, DatesNeeded.TradingDate
FROM Symb CROSS JOIN DatesNeeded
  • 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-27T22:44:05+00:00Added an answer on May 27, 2026 at 10:44 pm

    This:

    DatesNotNeeded AS
    (
         SELECT Date
         FROM tblDailyPricingAndVol
         WHERE (tblDailyPricingAndVol.Symbol = Symb.Symbol)
    ),
    

    Needs to be this:

    DatesNotNeeded AS
    (
         SELECT Date
         FROM tblDailyPricingAndVol inner join Symb on
             tblDailyPricingAndVol.Symbol = Symb.Symbol
    ),
    

    But your query still won’t work, since this:

    DatesNeeded AS
    (
         SELECT TradingDate
         FROM WideDateRange wdr
         WHERE NOT EXISTS (SELECT * FROM DatesNotNeeded)
    )
    

    Needs to be this:

    DatesNeeded AS
    (
         SELECT TradingDate
         FROM WideDateRange wdr
         WHERE NOT EXISTS (SELECT * FROM DatesNotNeeded d where d.Date = wdr.TradingDate)
    )
    

    But really, you can do this without CTEs, like this:

    select
        sm.Symbol,
        tb.TradingDate
    from
        tblSymbolsMain sm
        cross join tblTradingDays tb
        left join tblDailyPricingAndVol dp on
            sm.Symbol = dp.Symbol 
            and tb.TradingDate = dp.Date
    where
        tb.TradingDate between 
            dbo.LatestAvailableDataDownloadDateTime()
            and dbo.NextAvailableDataDownloadDatetime()
        and dp.Date is null
    

    This query grabs all the symbols from tblSymbolsMain and all the dates between your last and next available dates from tblTradingDays. Then it does a left join on tblDailyPricingAndVol and filters out any row that found a match.

    You could also use not exists in lieu of a left join, which I think is a bit clearer, too:

    select
        sm.Symbol,
        tb.TradingDate
    from
        tblSymbolsMain sm
        cross join tblTradingDays tb
    where
        tb.TradingDate between 
            dbo.LatestAvailableDataDownloadDateTime() 
            and dbo.NextAvailableDataDownloadDatetime()
        and not exists (
            select
                1
            from
                tblDailyPricingAndVol dp
            where
                dp.Symbol = sm.Symbol
                and dp.Date = tb.TradingDate
        )
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My last question was somewhat narrower than this one. I am interested to know
Okay, this one is the reverse of the last question I struggled with... I
Following on from my last question Sql Server query performance , and discovering that
This question is a slight extension of the one answered here . I am
Can any one help me with this problem? As in my last question, I
This is a followup to my last question . I now have a byte[]
I guess this is a continuation of the last question I asked: bulk insert
Ok, I'm going to try to make this more clear because my last question
This is similar to this question I asked last week. My dataGrid is populated
Hopefully the last NN question you'll get from me this weekend, but here goes

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.