The new forums will be named Coin Return (based on the most recent vote)! You can check on the status and timeline of the transition to the new forums here.
The Guiding Principles and New Rules document is now in effect.

SQL HALP Exists/Not Exists

DeebaserDeebaser on my way to work in a suit and a tieAhhhh...come on fucking guyRegistered User regular
edited September 2011 in Help / Advice Forum
Please help H/A. My code isn't working and I'm having a bit of a brainfart. Here's what I am trying to do:


I want to identify all the SOMETHING_NUMs that we have from an external feed that don't have corresponding object_ids on our internal table. object_ids are a 9 character string in the middle of SOMETHING_NUM.

What am I fucking up?


SELECT DISTINCT
SOMETHING_NUM
FROM
database..external_feed
WHERE
NOT EXISTS
(SELECT *
FROM db2..internal_tbl1 di,
database..external_feed
where
SUBSTRING(SOMETHING_NUM,3,9) = di.object_id)

Deebaser on

Posts

  • bowenbowen Sup? Registered User regular
    edited September 2011
    Try:
    SELECT DISTINCT SOMETHING_NUM 
    FROM database..external_feed 
    WHERE NOT EXISTS
      ( SELECT * FROM db2..internal_tbl1, di, database..external_feed di.object_id = (SUBSTRING(SOMETHING_NUM,3,9)))
    

    If that doesn't work, what error do you get?

    bowen on
    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
  • DeebaserDeebaser on my way to work in a suit and a tie Ahhhh...come on fucking guyRegistered User regular
    There's no error message. There's just no population. I know that there is a population because I did a run without the NOT EXISTS for a small sample date range.

    The problem is, I can't run the full history like that because it's pretty resource hoggy.

    @Bowen

  • DeebaserDeebaser on my way to work in a suit and a tie Ahhhh...come on fucking guyRegistered User regular
    Got it. Thanks Bowen!

    Please lock.

  • bowenbowen Sup? Registered User regular
    Sybase, fun!

    not a doctor, not a lawyer, examples I use may not be fully researched so don't take out of context plz, don't @ me
Sign In or Register to comment.