CASE STATEMENT THE DOES A LOOKUP

  • is this a correct syntax to populate a field name PHONES in my CUSTOMERS TABLE

    case when(d.phone = (SELECT phone from CALLS where exists(select home_phone, mobile, toll_free from CALLS2) Then 1 END 'PHONES'

  • Hi

    The simple answer is no. To get a better answer you should post up more information as outlined in this article Forum Etiquette: How to post data/code on a forum to get the best help[/url].

    A couple of notes on what you have posted.

    ...where exists(select home_phone, mobile, toll_free from CALLS2)...

    There is no join to calls in this, so if there is any rows in CALLS2 it will always return true.

    ... SELECT phone from CALLS where exists( ...

    Again, there is no join in this to your customers table so it is likely to return all the rows in the CALLS table

    ... d.phone = (SELECT phone ...

    In a situation like this you should use the IN operator rather than an =.

    Having said that I wouldn't be using a statement like that to update a column. I would post an update example, but I am worried about pointing you in the wrong direction.

    Post some additional information and someone will be able to point you in the right direction.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply