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.

Like, I could use some SQL help pls

DeebaserDeebaser on my way to work in a suit and a tieAhhhh...come on fucking guyRegistered User regular
I am trying to join two tables using something like a LIKE condition.

Basically in my dataset I have CUSORS, which are a varchar component of ISORS.
ISORS are in a different feed and are basically in a format that are have a two or three letter prefix to CUSORS.
Example:
Cusor: 1234567AA89
ISORS: XX1234567AA89

I'm drawing a blank here, but basically I want to pull all the ISORS that match the CUSORS in my dataset.


This is what I have so far. It doesn't work, because Im dumb. Can you even do a join on a like?

UPDATE #inst_wo_isor
SET ISor_cusor_db = i.ISOR
FROM
isin_us i
WHERE
#inst_wo_isor.CUSOR LIKE ('%' + i.ISOR)
AND #inst_wo_isor.CUSOR is not null


pls halp or advice

Posts

  • schussschuss Registered User regular
    edited November 2013
    If you can avoid it, don't use a like, as it's highly inefficient. Is it variable between the 2 and the 3 letter prefixes, or always 1 or the other?

    I would do something like
    SET Is_Cusor_Db = i_ISOR
    From
    isin_us_i
    WHERE
    RIGHT ( ISORS ,11 ) = #inst_wo_isor.CUSOR

    My syntax is crap, but the general idea is to do an exact match of the CUSOR to the right portion of the ISOR, eliminating the like.

    schuss on
  • LorekLorek Registered User regular
    I think your LIKE statement is backwards:
    i.ISORS LIKE '%' + #inst_wo_isor.CUSOR

    Or for one example:
    XX1234567AA89 is like 'any characters here' + 1234567AA89

  • TehSlothTehSloth Hit Or Miss I Guess They Never Miss, HuhRegistered User regular
    edited November 2013
    Is the length of Cusor always the same? I would use SUBSTRING

    Where
    (#inst_wo_isor.CUSOR = SUBSTRING(i.isor, 2,11) OR #inst_wo_isor.CUSOR = SUBSTRING(i.isor, 3,11)) AND #inst_wo_isor.CUSOR is not null

    edit: oh, hey, I like RIGHT better, that's interesting.

    TehSloth on
    FC: 1993-7778-8872 PSN: TehSloth Xbox: SlothTeh
    twitch.tv/tehsloth
  • schussschuss Registered User regular
    TehSloth wrote: »
    Is the length of Cusor always the same? I would use SUBSTRING

    Where
    (#inst_wo_isor.CUSOR = SUBSTRING(i.isor, 2,11) OR #inst_wo_isor.CUSOR = SUBSTRING(i.isor, 3,11)) AND #inst_wo_isor.CUSOR is not null

    edit: oh, hey, I like RIGHT better, that's interesting.

    Ha, I did the same thing. My pre-edit post was substring, then the little sql fairy in my head said "Use right you git".

    Glad to see other data people think the same way.

  • DeebaserDeebaser on my way to work in a suit and a tie Ahhhh...come on fucking guyRegistered User regular
    RRRRIIIIGGGHHHHTTT
    derp. i am dumb
    Thank you so much, you beautiful bastards!

Sign In or Register to comment.