Advertisement

10.04.2007 at 06:46AM PDT, ID: 22872027
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.8

LEFT OUTER vs LEFT

Asked by dbaSQL in MS SQL Server, Databases Miscellaneous, SQL Query Syntax

Tags: , ,

I do a gazillion different daily reports --- sql v2k --- at the moment, i am referring to my Daily and Month-to-Date reports.  Same logic, one just looks at current day, one looks at the entire month-to-date.   As of late, it's come to my attention that there are some variances between the reports that shouldn't be.  so i'm going in double checking all the logic is the same between the two (except for the time parms)

anyway, i used to do a bunch of IN lists.
-where endpoint IN (great big huge in list)
-CASE where lflag = this, then that.... a ton of these
-CASE where symbol = this, then that.... a ton of these

so, for perfomance reasons, I got rid of my IN lists, replacing each w/joins to the appropriate definitional tables, retrieving the values i need where exists.  but again, for whatever reason, i'm too high on the monthly.  or,this past monday (oct 1st) the two did not equate

like i said, i'm comparing the logic and i wonder if i may be inadvertently excluding from the dataset because of my LEFT JOINS.  Don't LEFT's only return where there are matches, yet LEFT OUTER will return all rows in the left table, wehter matched in the right or not.  yes?

i was just wondering --- might the current version down there exclude from the resultset?  if so, will the proposed new version take care of things?
and if LEFT vs LEFT OUTER changes nothing, are there any other suggestions regarding what the problem may be, or even how to improve the code at all?

current:

SELECT tr.EndPoint,
      ISNULL(lft.Description, ltrim(rtrim(tr.lflag))) AS Liquidity,
      sdd.Duration,
      Symbol,
      CAST(count(*) AS MONEY) as countOfTrades,
      SUM(tr.Quantity) AS 'Volume    ',
      SUM(tr.Quantity*CAST(tr.Price AS Money)) AS 'Total $   '
FROM database.dbo.historicaltable tr WITH (NOLOCK)
LEFT JOIN database.dbo.LFlagTranslate lft
      ON tr.lFlag = lft.LFlag
LEFT JOIN database.dbo.SymbolDurationDescription sdd
      ON tr.symbol LIKE sdd.SubSymbol
INNER JOIN database.dbo.grouptable
ON tr.endpoint = eg.endpoint
AND eg.epgroup = 'EQTY'
WHERE tradetime BETWEEN @start AND @stop
      AND tr.lflag NOT IN ('LA','LP')
GROUP BY
      tr.endpoint,
      ISNULL(lft.Description, ltrim(rtrim(tr.lflag))),
      tr.Symbol,
      sdd.Duration



proposed new:

SELECT tr.EndPoint,
    ISNULL(lft.Description, ltrim(rtrim(tr.lflag))) AS Liquidity,
    sdd.Duration,
    Symbol,
    CAST(count(*) AS MONEY) as countOfTrades,
    SUM(tr.Quantity) AS 'Volume    ',
    SUM(tr.Quantity*CAST(tr.Price AS Money)) AS 'Total $   '
FROM database.dbo.historicaltable tr WITH (NOLOCK)
INNER JOIN database.dbo.grouptable epg
    ON tr.endpoint = epg.endpoint  
LEFT OUTER JOIN database.dbo.LFlagTranslate lft
    ON tr.lFlag = lft.LFlag
LEFT OUTER JOIN database.dbo.SymbolDurationDescription sdd
    ON tr.symbol LIKE sdd.SubSymbol
WHERE tradetime BETWEEN @start AND @stop
    AND epg.epgroup = 'eqty'
    AND tr.lflag NOT IN ('LA','LP')
GROUP BY
    tr.endpoint,
    ISNULL(lft.Description, ltrim(rtrim(tr.lflag))),
    tr.Symbol,
    sdd.Duration

please advise.  any thoughts/guidance is very much appreciatedStart Free Trial
[+][-]10.04.2007 at 06:49AM PDT, ID: 20014081

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL Server, Databases Miscellaneous, SQL Query Syntax
Tags: inner, join, outer
Sign Up Now!
Solution Provided By: matthewspatrick
Participating Experts: 1
Solution Grade: A
 
 
[+][-]10.04.2007 at 06:53AM PDT, ID: 20014109

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.04.2007 at 06:56AM PDT, ID: 20014136

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628