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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:33:22+00:00 2026-06-15T05:33:22+00:00

I’m an extreme novice running SQL SERVER 2005. I have two tables that I’m

  • 0

I’m an extreme novice running SQL SERVER 2005. I have two tables that I’m putting together in a view. The first table just has 2 columns that go into the view. One column is an ID number and the other is name. The second table is where all the data is. The columns in that table are ID, Date, Hour, PriceType, MarketType, and Price. My goal is to have a view that filters PriceType to be a fixed value, and then takes the difference of Price when MarketType is DAM from the price with the MarketType is RTM. Right now that looks like the following….

SELECT dbo.nodes.commonname,
       dbo.nodes.node_id,
       da.pricedate,
       da.hour,
       rt.price            AS rtm,
       da.price            AS dam,
       da.price - rt.price AS dart
FROM   dbo.pnodes
       INNER JOIN dbo.pnode_prices AS da
               ON dbo.pnodes.node_id = da.pnode_id
       INNER JOIN dbo.pnode_prices AS rt
               ON dbo.pnodes.node_id = rt.pnode_id
                  AND da.pricetype = rt.pricetype
                  AND da.pricedate = rt.pricedate
                  AND da.hour = rt.hour
WHERE  ( da.pricetype = 'LMP' )
       AND ( da.markettype = 'DAM' )
       AND ( rt.markettype = 'RTM' ) 

This view doesn’t take so long by itself. Sometimes I want to take it another step and have the difference between 2 views where I’ll run a query that joins the above view and takes the difference of Price where view1.CommonName=abc and view2.CommonName=xyz. When I run that query it takes 10 times as long to run as it takes to run the simple view by itself. I assume that if I did things optimally that it wouldn’t take 10x the time. Is there any low hanging fruit that I can do to improve this?

  • 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-06-15T05:33:24+00:00Added an answer on June 15, 2026 at 5:33 am

    overall, your query looked ok, but running as a view, obviously isn’t working well for you. That said, I would like to offer a slight re-structuring of the query. Move the WHERE conditions into the JOIN components.

    Ensure you have an index on the CommonName on the nodes table you will apply a filter against. On the price_nodes table, have a composite index on ( node_id, markettype, pricetype ).

    SELECT 
          N.commonname,
          N.node_id,
          da.pricedate,
          da.hour,
          rt.price            AS rtm,
          da.price            AS dam,
          da.price - rt.price AS dart
       FROM
          dbo.pnodes N
    
             INNER JOIN dbo.pnode_prices AS da
                   ON N.node_id = da.pnode_id
                  AND da.markettype = 'DAM'
                  AND da.pricetype = 'LMP'
    
                INNER JOIN dbo.pnode_prices AS rt
                   ON da.node_id = rt.pnode_id
                  AND rt.markettype = 'RTM'
                  AND da.pricetype = rt.pricetype
                  AND da.pricedate = rt.pricedate
                  AND da.hour = rt.hour
    

    This way, the where clause can rely exclusively on your condition of company A vs B. The rest of the joins are based on their “node_id”. I’ve also made the join to “rt” linked from the “da” since the node_id is already from pNodes to the da.node_id, so use da.Node_id to rt.node_id. It might be the one thing the engine is getting stuck on.

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

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.