Home Forums SQL Server 2012 SQL Server 2012 - T-SQL Querying a Supersession Two Column Table with Multiple Supersessions in both Columns RE: Querying a Supersession Two Column Table with Multiple Supersessions in both Columns

  • p.barwick (2/4/2014)


    This, for example, returns 0 rows for the last segment.

    ..

    CREATE TABLE #Source

    (

    PartNo VARCHAR(20)

    ,PartDesc VARCHAR(100)

    ,Price MONEY

    );

    SELECT 'SFP500160','KIT BRAKE LINING',58.02;

    ...

    That's because you somehow lost the INSERT before SELECT when populating your #Source table. With nothing in #Source, the final query will always return 0 rows because of the INNER JOIN.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh![/I]

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.

    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?[/url]
    Since random numbers are too important to be left to chance, let's generate some![/url]
    Learn to understand recursive CTEs by example.[/url]
    [url url=http://www.sqlservercentral.com/articles/St