Sharktooth Sharktooth - 1 year ago 83
SQL Question

How does % operator in AND evaluate

Found this in the AND condition of LEFT OUTER JOIN between AA & DD


Can anyone explain what this is evaluating and how?

Answer Source

The LIKE operator does a string comparison but treats % and _ as wildcards matching any string and any single character, respectively. This is analoguous to * and ? in the shell.

DD.EMPL_ID LIKE '%' + AA.[Emp_Id]

looks like your DBM uses + for string concatenation (standard SQL would be ||). So if AA.[Emp_id] is 'hello', then that condition becomes

DD.EMPL_ID LIKE '%' + 'hello'

which is

DD.EMPL_ID LIKE '%hello'

which checks whether DD.EMPL_ID is an arbitrary string followed by hello, i.e. whether DD.EMPL_ID ends with hello.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download