• dwilliscp (11/14/2012)


    True, just a personal quirk. I find that when I am trying to think through something... I tend to code the thought process. Thus the outer join filtering where not NULL.

    Sean Lange (11/14/2012)


    dwilliscp (11/14/2012)


    Hmm thought it would do a line by line check.. turns out that my thought process was off anyway. Given that we have data here that is not in SAP, I can not do any conditional deletes. I will have to use the update statement to update existing records, instead of deleting and re-loading.

    However if the plan had not changed.. then the delete statement would still not have worked quite right. I still wonder how that would have worked. The idea was to have it select all records that existed and refresh only those... to get the list you would have to run the following SQL statement:

    Select plant.Plant

    from file_Plants as plant

    left outer join Plant_Master as mas

    on mas.Plant_CD = plant.Plant

    where NOT(mas.Plant_CD is NULL)

    Just my personal preference but I find this type of check to be far easier to read with a positive test.

    where mas.Plant_CD IS NOT NULL

    Of course in the case of this specific query why not just change the left join to an inner join since that is the result set you want to find. 😎

    I wouldn't call it "personal preference". It's wrong type of join, which can lead to worse performance.

    That is exactly what INNER JOIN is for, so better to be written as

    Select plant.Plant

    from file_Plants as plant

    inner join Plant_Master as mas

    on mas.Plant_CD = plant.Plant

    Now, as you select nothing from Plant_Master, you may find that the following will perform even better than INNER JOIN:

    Select plant.Plant

    from file_Plants as plant

    where exists (select 1 from Plant_Master as mas

    where mas.Plant_CD = plant.Plant)

    Above two samples, can be actually called as "personal preference", but again, you may find that EXIST will give slightly better performance, as query processor will know that you need nothing from Plant_Master table.

    _____________________________________________
    "The only true wisdom is in knowing you know nothing"
    "O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!":-D
    (So many miracle inventions provided by MS to us...)

    How to post your question to get the best and quick help[/url]